php MySQL Alter Table 在已经存在的字段之前或之后添加字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3379454/
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 09:31:45  来源:igfitidea点击:

MySQL Alter Table Add Field Before or After a field already present

phpmysql

提问by atwellpub

I have this, but it doesn't work:

我有这个,但它不起作用:

$query = "ALTER TABLE `".$table_prefix."posts_to_bookmark` 
            ADD `ping_status` INT( 1 ) NOT NULL BEFORE `onlywire_status`";

I appreciate it!

我很感激!

回答by Chris

$query = "ALTER TABLE `" . $table_prefix . "posts_to_bookmark` 
          ADD COLUMN `ping_status` INT(1) NOT NULL 
          AFTER `<TABLE COLUMN BEFORE THIS COLUMN>`";

I believe you need to have ADD COLUMNand use AFTER, not BEFORE.

我相信你需要拥有ADD COLUMN和使用AFTER,而不是BEFORE

In case you want to place column at the beginning of a table, use the FIRSTstatement:

如果要将列放在表的开头,请使用以下FIRST语句:

$query = "ALTER TABLE `" . $table_prefix . "posts_to_bookmark`
          ADD COLUMN `ping_status` INT(1) NOT NULL 
          FIRST";

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html