如何删除sql表的索引重复值

2025-02-23 17:56:48
推荐回答(2个)
回答1:

例,B1表中ID应为主键,但建表时未设,表中有重复,删除语句如下:
select id,max(c1) as c1,max(c2) as c2,... into #temptable from b1 group by id
go

delete from b1
go

insert into b1 select * from #temptable
go
drop table #temptable
go

回答2:

可以建立唯一索引,