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

解决方案 »

  1.   

    temp 前面加个#不就不用drop了?
      

  2.   

    加一个字段id
    alter table tablename add id int identity(1,1)not null
    go
    select * from tablename where id in(select min(id) from tablename group by 字段1)或临时表
    select id=identity(int,1,1),* into temp from tablename
    select * from temp where id in(select min(id) from temp group by 字段1)
    drop table temp
      

  3.   

    select top 1 * from youtable where 字段1=11
      

  4.   

    這裡有兩種情況:
    (1.) 對完全重復的記錄(即所有子段均重復)
         select distinct *
         into #temp
         from tablename
         GO
         truncate table tablename
         GO
         select *
         into tablename
         from #temp
         GO
         drop table #temp(2.)對部分關鍵字重復的記錄,如重復的字段為 name,address ;要求得到這兩個字段唯一的
        結果集.
        select identity(int,1,1) as id,*
        into #temp
        from tablename
        GO
        select min(id) as id
        into #tempyh
        from #temp
        group by name,address
        GO
        select *
        from #temp
        where id IN ( select id from #tempyh )
        GO