数据库中删除重复记录

来源:互联网 发布:乐视视频显示无网络 编辑:程序博客网 时间:2024/06/02 20:04

1,利用临时表来删除

 

A是原表,temp是临时表

 

select distinct *  into temp from A

 

delete from A

 

insert into A select * from temp

 

select * from A

 

 

2,利用自增字段

 

alter table A add columns_b int identity(1 ,1)

 

delete from A where columns_b not in(select max(columns_b) from A group by id,name....)

 

alter table A drop column columns_b