alter table add … before `code`?

你离开我真会死。 提交于 2019-12-01 14:07:29

问题


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?


回答1:


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



回答2:


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




回答3:


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;


来源:https://stackoverflow.com/questions/3402310/alter-table-add-before-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!