TA的每日心情 | 开心 2021-1-8 22:40 |
---|
签到天数: 652 天 [LV.9]以坛为家II
|
楼主 |
发表于 2010-12-23 14:19:32
|
显示全部楼层
删除表格中的重复数据
declare @name nvarchar(100)
declare cursor_游标名 cursor for --定义游标cursor1
select 需要查询重复的字段名 from 需要查询重复的表名 group by 需要查询重复的字段名 having count(需要查询重复的字段名)>1 --使用游标的对象(跟据需要填入select文)
open cursor_游标名
fetch next from cursor_游标名 into @name --将游标向下移1行,获取的数据放入之前定义的变量@id,@name中
while @@fetch_status=0 --判断是否成功获取数据
begin
delete 需要查询重复的表名 where 需要查询重复的字段名 in (
select 需要查询重复的字段名 from 需要查询重复的表名 group by 需要查询重复的字段名 having count(需要查询重复的字段名)>1) --进行相应处理(跟据需要填入SQL文)
fetch next from cursor_游标名 into @name --将游标向下移1行
end
close cursor_游标名 --关闭游标
deallocate cursor_游标名
|
|