数据库,唯一索引,重复数据处理
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
//唯一索引,重復(fù)數(shù)據(jù)處理
1、為母表建立唯一主鍵(主鍵為自增,此字段在后面刪除記錄時(shí)會(huì)用到),同時(shí)
建立和母表一樣的臨時(shí)表(此表要建立好唯一索引以免數(shù)據(jù)二次出錯(cuò)),記得
在作所有工作前要先備份母表。
2、查詢出重復(fù)記錄
SELECT * from imc_unity_login_role group by unity_id,uid HAVING count(unity_id+uid )>1
3、確認(rèn)數(shù)據(jù)是否正確(是不是要處理的重復(fù)數(shù)據(jù))
SELECT * from imc_unity_login_role where uid = 100126 order by unity_id
4、將重復(fù)數(shù)據(jù)放入臨時(shí)表中
insert into IMCDBserver.imc_unity_login_role_temp?
SELECT?
* from imc_unity_login_role group by unity_id,uid HAVING count(unity_id+uid )>1
5、刪除母表中的重復(fù)數(shù)據(jù)
DELETE from imc_unity_login_role where DBID_ in (SELECT DBID_ from imc_unity_login_role_temp)
6、為母表建立索引,OK搞定
轉(zhuǎn)載于:https://my.oschina.net/ltsoft/blog/663673
總結(jié)
以上是生活随笔為你收集整理的数据库,唯一索引,重复数据处理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Codeforces Beta Roun
- 下一篇: Fragment生命周期详解