mysql – 在列之后添加新列并定义默认值
作者:互联网
我正在尝试在另一列之后添加一列,同时还指定一个默认值.以下是我的尝试不起作用.
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
解决方法:
如果我这次正确读取documentation for alter table
…你只能指定后或默认,但不能同时指定两者.您可以通过使用after创建列,然后将其更改为具有默认值来解决此问题:
alter table pageareas add content_userDefined BIT( 1 ) NULL after content;
alter table pageareas alter content_userDefined set default 0;
标签:mysql,database,alter-table 来源: https://codeday.me/bug/20190530/1183709.html