游标去掉重复项

    技术2022-05-20  66

    在数据库的操作中我们经常会遇到表中一些字段重复,也许是标题重复,也许是内容重复,没关系有了这个游标你只需要修改相应的需要被检测的字段,@title 以及表名tsys_News 然后执行便可去掉所有重复项。

     

     

    declare @max integer,@title varchar(200)declare cur_rows cursor local for select title,count(*) from tsys_News group by title having count(*) > 1open cur_rowsfetch cur_rows into @title,@maxwhile @@fetch_status=0beginselect @max = @max -1set rowcount @maxdelete from tsys_News where title = @titlefetch cur_rows into @title,@maxendclose cur_rowsset rowcount 0


    最新回复(0)