SQL语句删除重复数据

时间:2023-12-26 12:10:13

1.如表中没有主键,先添加自动增长主键

alter table 表名 add 列名 int identity (1,1) primary key

2.删除重复数据

delete from 表名 where id not in
(select min(id) from 表名 group by id)

------id1为新增自增的列,id为原来没有自增的id列

delete from DeceasedInformation where id1 not in
(select MIN(id) from DeceasedInformation group by id)

SQL语句删除重复数据