删除表中重复记录

使用游标的

declare @max int,@id int
declare
cur_rows cursor local for
select
[ProjectId],count(*) from [ProjectTheme] group by[ProjectId] having count(*) >1
open cur_rows
fetch cur_rows into @id,@max
while  @@fetch_status=0
begin
select
@max = @max -1
set rowcount @max
delete from [ProjectTheme] where [ProjectId] = @id
fetch cur_rows into @id,@max
end
close
cur_rows
set rowcount 0

posted @ 2011-02-20 11:17  吕飞  阅读(211)  评论(0编辑  收藏  举报