Mechlar
Mechlar

Reputation: 4974

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

Upvotes: 5

Views: 9958

Answers (1)

Michael Fredrickson
Michael Fredrickson

Reputation: 37388

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;

Upvotes: 9

Related Questions