Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alter table add ... before `code`?

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?

like image 284
Hailwood Avatar asked Aug 04 '10 03:08

Hailwood


2 Answers

ALTER TABLE `tada_prod`.`action_6_weekly`
ADD COLUMN `id` INT NULL AUTO_INCREMENT UNIQUE FIRST;
like image 79
Ben Hoffstein Avatar answered Sep 22 '22 11:09

Ben Hoffstein


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

like image 40
php Avatar answered Sep 22 '22 11:09

php