3

I searched a lot on web, but couldn't find the answer for dropping multiple columns in single alter statement using SQL Server 2008.

I tried following query

ALTER TABLE TableToDropColumn DROP (Field2, Field3)

but it throws an error

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '('.

3 Answers 3

7
ALTER TABLE TableToDropColumn DROP COLUMN Field2, Field3

SQLFiddle demo

Sign up to request clarification or add additional context in comments.

Comments

2
ALTER TABLE TableToDropColumn DROP Field2, DROP Field3

1 Comment

ALTER TABLE TableToDropColumn DROP COLUMN Field2, DROP COLUMN Field3.... is the only way, that works in Postgres.
2
ALTER TABLE TableToDropColumn DROP COLUMN Field2, Field3

On a side note:

You may also need to know how to get rid of the wasted space which is created after the above command.You can do ALTER TABLE ... REBUILD. Actually DROP COLUMN does not physically remove the data and the space is consumed even for records added after the columns were dropped. So thats why you need to use ALTER TABLE ... REBUILD to get rid of the wasted space

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.