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

后端 未结 13 1098
星月不相逢
星月不相逢 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:58

    For MySQL (ver 5.6), you cannot do multiple column drop with one single drop-statement but rather multiple drop-statements:

    mysql> alter table test2 drop column (c1,c2,c3);
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(c1,c2,c3)' at line 1
    mysql> alter table test2 drop column c1,c2,c3;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'c2,c3' at line 1
    mysql> alter table test2 drop column c1, drop column c2, drop c3;
    Query OK, 0 rows affected (0.64 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> 
    

    BTW, drop is shorthanded for drop column as you can see from drop c3 above.

提交回复
热议问题