34,838
社区成员




declare @s varchar(8000)
alter table PricesMonthly add id int,checks bigint
set @s ='
declare @i int set @i = 1
update PricesMonthly set id = @i,@i= @i + 1,checks = checksum(*)
delete a from PricesMonthly a where exists(select 1 from PricesMonthly where id<a.id and checks=a.checks)
alter table PricesMonthly drop column id,checks'
exec(@s)
select * from PricesMonthly
select distinct * into # from ta
truncate table ta
insert into ta select * from #
alter table ta add id int
declare @i int
set @i = 1
update ta set id = @i,@i= @i + 1
delete a from ta a where exists(select 1 from id<a.id and 字段比较)
alter table ta drop table id
declare @max integer,@id integer,@idcode
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