2012-04-13 33 views
4

我想在另一列之後添加一列,同時指定一個默認值。以下是我的嘗試不起作用。在列後添加新列並定義默認值

alter table pageareas add content_userDefined BIT(1) NULL default 0 after content; 

如果我刪除 「之後的內容」 它的工作原理:

alter table pageareas add content_userDefined BIT(1) NULL default 0; 

如果我刪除 「默認0」 它的工作原理:

alter table pageareas add content_userDefined BIT(1) NULL after content; 

我怎樣才能做到之後將它添加指定的列,同時也定義了一個默認值?

我使用的是MySQL 5.1.36

回答

5

如果我正確地讀documentation for alter table這個時候......你只能指定afterdefault,但不能同時使用。您可以解決此通過使用after創建列,然後改變它有default

alter table pageareas add content_userDefined BIT(1) NULL after content; 
alter table pageareas alter content_userDefined set default 0; 
+0

這是票,謝謝! – UpHelix 2012-04-13 17:06:00