select distinct * into # from tb go truncate table tb go insert tb select * from # go drop table #
如果col1+col2都相同,则只能使用临时表了.
--------------删除所有重复记录delete a where col1 in (select col1 from a group by col001 having count(*)>1)------------------全部重复 保留一条数据,select * into #b from a ---备份truncate table #binsert into a select disitnct * from #b ---------------某个字段重复,只保留一条数据库(用游标)-------------------------用游标过滤重复记录 declare @aa varchar(60) declare www cursor for select h_name from join_product_ty_bf open www fetch next from www into @aa while(@@fetch_status=0) begin fetch next from www into @aa if exists (select h_name from join_product_ty_bf where h_name like @aa group by h_name having count(*)>1) delete join_product_ty_bf where current of www end
go
truncate table tb
go
insert tb select * from #
go
drop table #
如果col1+col2都相同,则只能使用临时表了.
select disitnct * from #b
---------------某个字段重复,只保留一条数据库(用游标)-------------------------用游标过滤重复记录
declare @aa varchar(60)
declare www cursor for
select h_name from join_product_ty_bf
open www
fetch next from www into @aa
while(@@fetch_status=0)
begin
fetch next from www into @aa
if exists
(select h_name from join_product_ty_bf where h_name like @aa group by h_name having count(*)>1)
delete join_product_ty_bf where current of www
end