123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- --由于历史数据库表结构与主数据库不一样,
- --主数据库表有索引,但历史数据库许多表没有添加唯一索引,造成历史数据库重复数据一大片
- --在修复历史数据结构前,先要清除重复的记录,只留一条;
- use [2014]
- --1.client表,主数据库有唯一索引,清除2014多余的重复记录;
- --image字段不能distinct;
- if exists(select name from syscolumns where id=object_id('client') and name='photo')
- alter table [client] drop column [photo]
- go
- select distinct * into #temp from client
- go
- drop table client
- go
- select * into client from #temp
- go
- drop table #temp
- go
- --2.dindansp表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindansp
- go
- drop table dindansp
- go
- select * into dindansp from #temp
- go
- drop table #temp
- go
- --3.photoprint表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from photoprint
- go
- drop table photoprint
- go
- select * into photoprint from #temp
- go
- drop table #temp
- go
- --4.dindanbukuan表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindanbukuan
- go
- drop table dindanbukuan
- go
- select * into dindanbukuan from #temp
- go
- drop table #temp
- go
- --5.dindanbukuan2表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindanbukuan2
- go
- drop table dindanbukuan2
- go
- select * into dindanbukuan2 from #temp
- go
- drop table #temp
- go
- --6.dindan表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindan
- go
- drop table dindan
- go
- select * into dindan from #temp
- go
- drop table #temp
- go
- --7.burncdreg表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from burncdreg
- go
- drop table burncdreg
- go
- select * into burncdreg from #temp
- go
- drop table #temp
- go
- --8.digitalwork表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from digitalwork
- go
- drop table digitalwork
- go
- select * into digitalwork from #temp
- go
- drop table #temp
- go
- --9.mywork表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from mywork
- go
- drop table mywork
- go
- select * into mywork from #temp
- go
- drop table #temp
- go
- --10.dindanjd表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindanjd
- go
- drop table dindanjd
- go
- select * into dindanjd from #temp
- go
- drop table #temp
- go
- --11.dindansp2表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindansp2
- go
- drop table dindansp2
- go
- select * into dindansp2 from #temp
- go
- drop table #temp
- go
- --12.dindansp3表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from dindansp3
- go
- drop table dindansp3
- go
- select * into dindansp3 from #temp
- go
- drop table #temp
- go
- --13.singleincome表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from singleincome
- go
- drop table singleincome
- go
- select * into singleincome from #temp
- go
- drop table #temp
- go
- --14.singleincomemoney表
- --忽略,主数据库无唯一索引;
- go
- select distinct * into #temp from singleincomemoney
- go
- drop table singleincomemoney
- go
- select * into singleincomemoney from #temp
- go
- drop table #temp
- go
|