MySql数据库设置修改主键自增长

MySql数据库设置修改主键自增长

  • 库表中未设置为主键
    • alter table t1 change column id id int not null primary key auto_increment;
  • 库表中已设置为主键
    • alter table t1 change column id id int auto_increment;

库表中未设置为主键

alter table t1 change column id id int not null primary key auto_increment;

库表中已设置为主键

alter table t1 change column id id int auto_increment;

注意:需要把数据中已存在主键值为0的记录,改成不为0且不重复的任意数字。

你可能感兴趣的:(数据库)