为已存在数据的表加主键

来源:互联网 发布:隔壁老王 知乎 编辑:程序博客网 时间:2024/06/06 01:39
alter table `表格名` add column `列名` int not null auto_increment primary key comment '主键' first;    

上面语句表示给某个表格添加一个自动增长的主键字段,并且将该字段放在第一列。

如果你想放到其他列后面,可以将上面sql语句中的 first 换成  after `已经有的列名


alter table `customfield_person_value` add column `ID` int not null auto_increment   primary key comment '主键'    first;   
0 0
原创粉丝点击