2013-07-31 53 views
0
ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT(0) 

當我這樣做時,出現此錯誤:#1064 - 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本的手冊,在第二行'(0)'附近使用正確的語法。添加新列時發生ALTER TABLE錯誤

任何想法爲什麼?謝謝!

回答

0

DEFAULT子句的語法只接受不是表達(甚至常數)。見http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html

The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression.


具體而言,您必須刪除括號:

ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT 0 
0

嘗試:

ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT '0' 
0

試試這個:

ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT 0;