有一個表裡面有某個字段出現重復記錄,怎樣保留重復記錄中的第一條記錄
select *,identity(int,1,1) ID into #t1 from table1
delete a
from #t1 a
where ID > (select min(ID) from #t1 where field1=a.fIEld1 and
field2=a.field2 and ... fieldn=a.fIEldn)
trancate table table1
alter table #t1 drop column ID
insert into table1 select * from #t1
也許可以這樣,簡便些
select distinct * into #t1 from table1
trancate table table1
insert into table1 select * from #t1