Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new column after column and defining a default

I am trying to add a column after another column while also specifying a default value. Below is my attempt that does not work.

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

If I remove "after content" it works:

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

And if I remove "default 0" it works:

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

How can I accomplish adding it after a specified column while also defining a default value?

I am using MySql 5.1.36

like image 207
UpHelix Avatar asked Apr 13 '12 16:04

UpHelix


1 Answers

If I'm reading the documentation for alter table correctly this time... you're only able to specify after or default, but not both. You could work around this by creating the column using after, and then altering it to have the default:

alter table pageareas add content_userDefined BIT( 1 ) NULL after content;
alter table pageareas alter content_userDefined set default 0;
like image 165
Michael Fredrickson Avatar answered Sep 23 '22 01:09

Michael Fredrickson