2011-11-01 269 views
4

我正在嘗試將列添加到現有的用戶表中,但它不起作用。我得到:MySQL alter table命令不起作用

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 'unsigned default 0 after users_id' at line 1 

這裏是我的命令:

[email protected]:test> alter table users add column users_is_active tinyint(3) not null unsigned default 0 after users_id; 

,除非我並沒有說明「不空」正確,我在做什麼錯? 由於

+1

你能試換不空和無符號彼此? – spicavigo

回答

19

ALTER TABLE用戶添加列users_is_active TINYINT(3)不爲空的無符號值0 users_id後;

TINYINT(3) UNSIGNED是類型。 NOT NULL不屬於TINYINT(3)UNSIGNED之間。相反,說TINYINT(3) UNSIGNED NOT NULL(等)。

1

移動unsigned接近tinyint

alter table users 
    add column users_is_active tinyint(3) unsigned not null default 0 
    after users_id;