首页 > 技术文章 > mysql添加一列,并设置自增

jiguang321 原文

在数据库中添加一列,并设置自增

注意设置自增时要将该字段设置为主键,如果不指定插入位置则默认为列名的最后。

1 alter table test.student add column indexxx int(14) primary key auto_increment;

指定插入在某一列之后

 1 alter table test.student add column indexxx int(14) primary key auto_increment after 列名; 

指定插入到第一列

 1 alter table test.student add column indexxx int(14) primary key auto_increment after first; 

推荐阅读