alter table t add id int identity(1,1)
delete from t where id not in (select min(id) from t group by 序号)
alter table t drop column id

解决方案 »

  1.   

    alter table t add id int identity(1,1)
    go
    delete from t where id not in (select min(id) from t group by un)
    alter table t drop column id
      

  2.   

    alter table t add id int identity(1,1)
    go
    delete from t where id not in (select min(id) from t group by un)
    go
    alter table t drop column id
    go
      

  3.   

    --检索重复的序号出来
    select 序号 from 表 group by 序号 having count(*)>1
      

  4.   

    --删除重复的序号
    alter table 表 add id int identity(int,1,1)
    godelete a 
    from 表 a left join(
    select id=min(id) from 表 group by 序号
    )b on a.id=b.id
    where b.id is null
    goalter table 表 drop column id
      

  5.   

    select distinct * into temp from table1
    truncate table table1
    insert into table1 select * from temp
    drop table temp
      

  6.   

    --删除重复的序号
    alter table 表 add id int identity(1,1)
    godelete a 
    from 表 a left join(
    select id=min(id) from 表 group by 序号
    )b on a.id=b.id
    where b.id is null
    goalter table 表 drop column id
      

  7.   

    我帖個好方法:
    Create @temp table(序号)INSERT INTO @temp 
    SELECT 序号 from T_table group by 序号 having count(*)>1DELETE T_table
    WHERE 序号 IN (SELECT 序号 from T_table group by 序号 having count(*)>1)INSERT INTO T_table
    SELECT * from @temp
      

  8.   

    Sorry, 上面有句錯了.
    Create @temp table(序号)換成Decimal @temp table(序号 Bigint)
      

  9.   

    如果表中没有自增ID,可以用一个中间表来做:
    select distinct * into b from adelete from ainsert into a select * from b若有ID:delete from a where id not in(select min(id)  from a group by col  having count(*)>1)