有关Mysql设置表主键id从1开始递增
今天在创建新表的时候,想要省事儿,直接复制了原来的表,在原来的表字段基础上进行修改,发现在测试新增的时候,第一行的id不是1,是在原来表的基础上加1,看着不好看,于是,有了以下方案。
//删除原来的主键值 alter table xxx drop id; // 重新从1开始编号,使它连续 alter table xxx add id int not null primary key auto_increment first;
今天在创建新表的时候,想要省事儿,直接复制了原来的表,在原来的表字段基础上进行修改,发现在测试新增的时候,第一行的id不是1,是在原来表的基础上加1,看着不好看,于是,有了以下方案。
//删除原来的主键值 alter table xxx drop id; // 重新从1开始编号,使它连续 alter table xxx add id int not null primary key auto_increment first;