如题,我没有设主键,如果用户输入两条完全相同的记录,删除语句如下:
delete from 表名 where 条件
可是这样就会把这两条记录一起删除,我想留一条记录,只删一条怎么办?

解决方案 »

  1.   

    这种情况下游标是无法定位的,最好select distinct * into #tem from xxx
    然后处理
      

  2.   

    select distinct * into #tem from xxx
    drop table xxx
    select * into xxx from #tem
      

  3.   

    先insert into #aaa select distinct * from 表名 where 条件
    再delete from 表名 where 条件
    再insert into 表名 select * from  #aaa 
    大概就是这样
      

  4.   

    oracle下可以这么做:
    delete from table1 t1 where rowid=(select min(rowid) from table1 t2 where t2.field1=t1.filed1) and 你的条件
    table1.field1是你可以确定有重复记录的条件字段,如果需要多个字段才能确定重复,就是t2.field1=t1.filed1 and t2.field2=t1.filed2 ... and t2.fieldn=t1.filedn
      

  5.   

    像下面这样即可DECLARE cur CURSOR
       FOR SELECT * FROM 表名 where 条件
    OPEN cur
    FETCH NEXT FROM curDELETE FROM 表名
    WHERE CURRENT OF curCLOSE cur
    DEALLOCATE cur