当前位置: 代码迷 >> Sql Server >> 删除重复字段解决方案
  详细解决方案

删除重复字段解决方案

热度:205   发布时间:2016-04-27 19:28:31.0
删除重复字段
select id 
from T
where NAME='T'
GROUP BY ID
HABING COUNT (ID)>=2

如何删除上表中
重复的字段
如重复1条 删除1条
重复2 则删除2
始终保持该表中1条唯一记录

------解决方案--------------------
alter table T add rowid int identity(1,1)
go

delete a from T a where exists(select 1 from T where id=a.id and rowid<a.rowid)
go

alter table T drop column rowid
go
------解决方案--------------------
select distinct id into #
TRUNCATE TABLE t
insert into t select * from #
drop table #
  相关解决方案