ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT(0)
當我這樣做時,出現此錯誤:#1064 - 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本的手冊,在第二行'(0)'附近使用正確的語法。添加新列時發生ALTER TABLE錯誤
任何想法爲什麼?謝謝!
ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT(0)
當我這樣做時,出現此錯誤:#1064 - 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本的手冊,在第二行'(0)'附近使用正確的語法。添加新列時發生ALTER TABLE錯誤
任何想法爲什麼?謝謝!
爲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
嘗試:
ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT '0'
從缺省值刪除括號。
試試這個:
ALTER TABLE mytable ADD mycolumn INT NOT NULL DEFAULT 0;