123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- declare
- @max integer,
- @id integer
- declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) > 1
- open cur_rows
- fetch cur_rows into @id,@max
- while @@fetch_status=0
- begin
- select @max = @max -1
- set rowcount @max
- delete from 表名 where 主字段 = @id
- fetch cur_rows into @id,@max
- end
- close cur_rows
- set rowcount 0
- select distinct * from tableName
- select distinct * into
- drop table tableName
- select * into tableName from
- drop table
- select identity(int,1,1) as autoID, * into
- select min(autoID) as autoID into
- select * from
- delete from 表名 where 重复字段名 in (select 重复字段名 from 表名 group by 重复字段名 having count(重复字段名) > 1) and id not in (select min(id) from 表名 group by 重复字段名 having count(重复字段名 )>1)
|