在已经存在的字段之前或之后添加字段

我有这个,但是不管用:

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

我很感激!

149889 次浏览
$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.

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

$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