mysql给已经存在的主键添加自增

mysql给已经存在的主键添加自增

第一种方案:

MySQL给已存在的表添加自增主键
alter table tablename add id int(11) primary key AUTO_INCREMENT; # 添加自增主键

第二种方案:

代码如下

第一步:给 id 增加auto_increment 属性
alter table tablename modify id int(11)  auto_increment;

第二步:给自增值设置初始值
alter table bu_staff  auto_increment=10000; 

涉及到问题:

关于mysql出现#1063 - Incorrect column specifier for column 'id'的问题的解决出现这个表示如果设置了自动增长,字段类型应该设置为int整型。

版权声明:本文为weixin_42134712原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。