欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sql2000数据库清除重复数据的二种方法

程序员文章站 2023-12-01 23:49:10
使用游标实现复制代码 代码如下:declare @id1 int,@oldid int,@e_recordid int ,@olde_recordid intdeclare...

使用游标实现

复制代码 代码如下:

declare @id1 int,@oldid int,@e_recordid int ,@olde_recordid int
declare price cursor
for select id ,e_recordid from evaeve order by  e_recordid desc
open price
fetch next from price  into @oldid,@olde_recordid
while @@fetch_status  = 0
begin
fetch next from price  
into @id1,@e_recordid

if @olde_recordid=@e_recordid
begin
  delete from evaeve where id=@id1
end
set @oldid=@id1
set @olde_recordid=@e_recordid
end 
close price
deallocate price

使用sql语句实现

复制代码 代码如下:

delete   from evaeve where id not in(  select max(id)  from evaeve group by   e_recordid)