简体   繁体   English

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

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

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! 我很感激!

$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 COLUMN and use AFTER , not BEFORE . 我相信你需要有ADD COLUMN并使用AFTER ,而不是BEFORE

In case you want to place column at the beginning of a table, use the FIRST statement: 如果要将列放在表的开头,请使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM