add unique index 注意事項


 

給業務添加唯一索引之前,必須核對當前的數據是否違反唯一索引約束:

 

檢測:


select
count( distinct app_id,count_date,cluster,priority) from events ; select count( *) from events ; select app_id,count_date,cluster,priority ,count(*) from events group by app_id,count_date,cluster,priority having count(*) >1 limit 20;

 

 

違反約束:

alter table events  add unique index uk_app(app_id,count_date,cluster,priority);       

ERROR 1062 (23000): Duplicate entry '2882303761517233197-2020-09-21-ALL-1' for key 'uk_id'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM