;

Drop Multiple Columns from a Single Table in SQL Server


Tutorialsrack 04/10/2019 SQL Server

In this article, we will learn how to DROP multiple columns from a single table in SQL Server. 

Learn Step By Step SQL 

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.

Example - Script for creating a table in tempdb
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:

Example - 1st way 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:

Example - 2nd way to Drop Multiple Columns
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!


Related Posts



Comments

Recent Posts
Tags