删除Table中完全重复记录 SQL语句

删除Table中完全重复记录 SQL语句

Create Table ReRowTest
(
ID int not null,
Name varchar(50)
)
insert into ReRowTest values(1,3)
insert into ReRowTest values(1,3)
insert into ReRowTest values(1,3)
insert into ReRowTest values(1,3)
insert into ReRowTest values(2,4)
insert into ReRowTest values(2,4)
insert into ReRowTest values(2,4)
insert into ReRowTest values(3,5)
insert into ReRowTest values(3,5)
insert into ReRowTest values(3,5)

SQL语句:

Select Distinct * into #tempTable From ReRowTest
Delete From ReRowTest
insert ReRowTest Select * From #tempTable
Drop table #tempTable

Select * From ReRowTest 结果为:

ID Name
1 3
2 4
3 5

如果常用可以封装成SQL存储过程

转载请注明:代码家园 » 删除Table中完全重复记录 SQL语句

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)