利用 Sql Server 游标删除重复记录
2010-01-27 10:35
211 查看
这段时间因项目需要导入原有的数据到新库中,遭遇了数据重复的问题,需删除重复的数据。我采用游标的方法解决此问题。 Sql 语句如下以免忘记。
删除重复数据,只保留记录号最大的declare mycursor cursor
for
select addinip from testdb group by addinip having count(addinip)>1
open mycursor
declare @ip sysname
fetch next from mycursor into @ip
while(@@fetch_status=0)
begin
print @ip
declare @aid int
select @aid=max(autoid) from testdb where addinip=@ip
print @aid
-- 删除重复数据,只保留记录号最大的那条记录
delete from testdb where autoid <> @aid and addinip=@ip
fetch next from mycursor into @ip
end
close mycursor
deallocate mycursor
删除重复数据,只保留记录号最大的declare mycursor cursor
for
select addinip from testdb group by addinip having count(addinip)>1
open mycursor
declare @ip sysname
fetch next from mycursor into @ip
while(@@fetch_status=0)
begin
print @ip
declare @aid int
select @aid=max(autoid) from testdb where addinip=@ip
print @aid
-- 删除重复数据,只保留记录号最大的那条记录
delete from testdb where autoid <> @aid and addinip=@ip
fetch next from mycursor into @ip
end
close mycursor
deallocate mycursor
相关文章推荐
- 利用 Sql Server 游标删除重复记录
- 利用 Sql Server 游标删除重复记录
- 删除表的重复记录(利用游标)
- 利用row_number over 函数删除重复记录
- 快速删除重复记录,SQL Server如何实现
- SQL Server 2005 中删除重复记录
- Sql Server表中删除重复记录最简单方法(多字段重复)
- SQL SERVER 删除重复记录
- 在SQL Server中快速删除重复记录
- 在SQL Server中快速删除重复记录(多图)
- 在SQL Server中快速删除重复记录
- 在SQL Server中快速删除重复记录
- SQL Server 2000删除表中的重复记录
- 在SQL Server中快速删除重复记录
- SQL Server 2005删除重复记录的新方法
- Oracle利用rowid删除表中重复记录
- 在SQL Server中快速删除重复记录
- 有关重复记录的删除(SQL SERVER)(不是很好的方法,可以参考一下,有待更新)
- 在Oracle中如何利用Rowid查找和删除表中的重复记录
- 在Oracle中利用Rowid查找和删除表中的重复记录