How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

后端 未结 13 1097
星月不相逢
星月不相逢 2020-12-22 18:17

I would like to write a single SQL command to drop multiple columns from a single table in one ALTER TABLE statement.

From MSDN\'s ALTER TABLE documenta

13条回答
  •  無奈伤痛
    2020-12-22 18:45

    create table test (a int, b int , c int, d int);
    alter table test drop column b, d;
    

    Be aware that DROP COLUMN does not physically remove the data, and for fixed length types (int, numeric, float, datetime, uniqueidentifier etc) the space is consumed even for records added after the columns were dropped. To get rid of the wasted space do ALTER TABLE ... REBUILD.

提交回复
热议问题