【问题标题】:Adding new column after column and defining a default在列之后添加新列并定义默认值
【发布时间】:2012-04-13 16:40:13
【问题描述】:

我正在尝试在另一列之后添加一列,同时还指定默认值。以下是我的尝试,但不起作用。

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

【问题讨论】:

    标签: mysql database alter-table


    【解决方案1】:

    如果我这次正确阅读了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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多