In this article, we will learn how to DROP multiple columns from a single table in SQL Server.
First, let us create a test table with multiple columns in a temporary database. Here is the script for creating a table in a temporary database.
USE tempdb
GO
CREATE TABLE MyTable (ID INT, Column1 INT, Column2 INT, Colcolumn3 INT)
GO
Now, there are two ways to drop multiple columns from a single table, the first way is to drop a one column at a time which is more time consuming, here is the query to DROP
columns:
ALTER TABLE MyBigTable
DROP COLUMN Column1
GO
ALTER TABLE MyBigTable
DROP COLUMN Column3
GO
Or you can use a better approach to DROP
a multiple columns from a single table, Here you can use a single ALTER
statement to DROP
multiple columns from a table, to drop a multiples columns from a table a query is as follows:
ALTER TABLE MyTable
DROP COLUMN Column1, Column3
GO
I hope this article will help you to understand the simple trick to DROP multiple columns from a single table in SQL Server.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments