php MySQL删除多列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15823498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:01:27  来源:igfitidea点击:

MySQL Drop Multiple Columns

phpmysql

提问by Cory Nickerson

I'm trying to drop multiple columns, but having some trouble. The syntax below works when I do ALTER TABLEand ADDwith multiple values in the brackets ()but it doesn't work with DROP COLUMN. Am I using the wrong syntax?

我正在尝试删除多个列,但遇到了一些麻烦。下面,当我做作品的语法ALTER TABLEADD用括号多个值(),但它不工作DROP COLUMN。我使用了错误的语法吗?

    $table3 = "
        ALTER TABLE $table3_name
        DROP COLUMN (
            user_firstname,
            user_lastname,
            user_address,
            user_address2,
            user_city,
            user_state,
            user_zip,
            user_phone
        );
    ";

回答by void

ALTER TABLE `tablename`
DROP `column1`,
DROP `column2`,
DROP `column3`;

回答by MANISH ZOPE

To drop multiple columns actual syntax is

删除多列的实际语法是

alter table tablename drop column col1, drop column col2 , drop column col3 ....

So for every column you need to specify "drop column" in Mysql 5.0.45. This is same as that of above answer. Just adding one point here. Alter table wont free up the actual space on the disk. So run optimize table on after running optimize table.

因此,对于每一列,您需要在 Mysql 5.0.45 中指定“删除列”。这与上面的答案相同。这里只加一分。更改表不会释放磁盘上的实际空间。所以在运行优化表之后运行优化表。