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

后端 未结 13 1084
星月不相逢
星月不相逢 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条回答
  •  Happy的楠姐
    2020-12-22 19:00

    For SQL Server:

    ALTER TABLE TableName
        DROP COLUMN Column1, Column2;
    

    The syntax is

    DROP { [ CONSTRAINT ] constraint_name | COLUMN column } [ ,...n ] 
    

    For MySQL:

    ALTER TABLE TableName
        DROP COLUMN Column1,
        DROP COLUMN Column2;
    

    or like this1:

    ALTER TABLE TableName
        DROP Column1,
        DROP Column2;
    

    1 The word COLUMN is optional and can be omitted, except for RENAME COLUMN (to distinguish a column-renaming operation from the RENAME table-renaming operation). More info here.

提交回复
热议问题