<span>add unique index 注意事项</span>

 

给业务添加唯一索引之前,必须核对当前的数据是否违反唯一索引约束:

 

检测:


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'

 

全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-23 18:34
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务