常常會有資料表沒有設定Primary Key
造成資料重複匯入
要如刪除重複部份
程序如下
--建置一個TEMP TABLE
drop table #A
create table #A(i int,s nvarchar(100))
--把來源資料下group by 並限制資料筆數是兩筆以上的加以匯入
insert into #A
select * from SourceTable
where iGroup in(
select iGroup from SourceTable
group by iGroup
having count(*) >1
)
--刪除重複的資料
delete AdminGroup
where iGroup in(
select iGroup from SourceTable
group by iGroup
having count(*) >1
)
--最後把整理匯入的Temp TABLE資料匯入即可
insert into SourceTable
select distinct i,s from #A
GH教學
搜尋
SQL刪除重複資料,一次搞定
張貼者:
Godhelp
at
2009年10月26日 星期一
標籤: SQL
0 意見:
張貼留言