1.备份表结构 create table table_bak like table_name; 2.备份表数据 insert into table_bak select * from table_name; 3.删除原来主键字段(如id) alter table table_name drop id; 4.添加主键,自增,放在第一位 alter table table_name add id int(11) primary key auto_increment first; 搞定 5.检查没问题…
(2.10)Mysql之SQL基础——约束及主键重复处理 关键词:mysql约束,批量插入数据主键冲突 [1]查看索引: show index from table_name; [2]查看有约束的列:select * from information_schema.key_column_usage where table_schema= 'db_name' and table_name = 'table_name'; [3]查看有约束的表及表约束类型:select * from informat…
原文链接:https://blog.csdn.net/RuobaiMEN/article/details/79794199 MySQL数据库表中有自增主键ID,当用SQL插入语句中插入语句带有ID列值记录的时候: 如果指定了该列的值,则新插入的值不能和已有的值重复,而且必须大于其中最大的一个值: 也可以不指定该列的值,只将其他列的值插入,让ID还是按照MySQL自增自己填: 具体: 1.创建数据库 create table if not exists userInfo ( id int PRIM…