SQL修改主键

855 阅读1分钟

1.删除多余重复数据,仅保留一条

delete from '表名' m
where (m.'主键名') in (select t.'主键名' from '表名' t group by t.'主键名' having count(*)>1)
and rowid not in (select min(rowid) from '表名' group by '主键名' having count(*)>1)

2.删除主键约束

alter table '表名' drop constraint '主键约束名'

3.添加主键约束

alter table '表名' add constraint '主键约束名' primary key('主键名')