Question

ALTER TABLE tada_prod.action_6_weekly ADD COLUMN id INT NULL AUTO_INCREMENT UNIQUE AFTER member_id;

works,

so i thought, to add the column as the first column i could do

ALTER TABLE `tada_prod`.`action_6_weekly`     ADD COLUMN `id` INT NULL AUTO_INCREMENT UNIQUE BEFORE `code`;

but i get a syntax error, what is the correct syntax?

Was it helpful?

Solution

ALTER TABLE `tada_prod`.`action_6_weekly`
ADD COLUMN `id` INT NULL AUTO_INCREMENT UNIQUE FIRST;

OTHER TIPS

You can add column only after particular field or at first not before. The mysql query for add column after particular filed is:
ALTER TABLE table_name ADD COLUMN column_name VARCHAR(30) AFTER column_name

Actually,

alter table table_name ADD column_name VARCHAR(12) NOT NULL BEFORE specific_column_name;

This command is not allowed in mySQL syntax. If you use it I think you get

" ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'before specific_column_name' at line 1 " message.

You can try:

ALTER TABLE table_name ADD column_name VARCHAR(12) NOT NULL FIRST;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top