網(LieHuo.Net)教程 數據庫的使用過程中由于程序方面的問題有時候會碰到重復數據,重復數據導致了數據庫部分設置不能正確設置……
方法一
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 #Tmp from tableName drop table tableName select * into tableName from #Tmp drop table #Tmp |
select identity(int,1,1) as autoID, * into #Tmp from tableName select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID select * from #Tmp where autoID in(select autoID from #tmp2) |