MySQL 创建唯一索引忽略对已经重复数据的检查

匿名 (未验证) 提交于 2019-12-02 22:06:11

MySQL 创建唯一索引忽略对已经重复数据的检查

# 重复数据 mysql> select aid,count(aid) as total ,email,tel_no,account_type,exten,passwd  from fudao_admin    group by user_name having total> 1; +-------+-------+--------------------------+--------+--------------+-------+----------------------------------+ | aid   | total | email                    | tel_no | account_type | exten | passwd                           | +-------+-------+--------------------------+--------+--------------+-------+----------------------------------+ |   256 |     5 |                          |        |            0 |       |                                  | |  4712 |     2 | bin.liu@wenba100.com     | 0      |            0 |       | 1afc079897c2de73022540f7c31db632 | |  1070 |     2 | feng.wang@wenba100.com   |        |            0 |       | c81103a50f7b7748303ede9726eed91a | | 10429 |     2 | jingxuan.li@wenba100.com | 0      |            0 | 1090  | 9bd7aa138ff1486e1285a412bda934dd | | 10425 |     2 | 843633577@qq.com         | 0      |            0 |       | 96e79218965eb72c92a549dd5a330112 | | 10426 |     2 | 843633577@qq.com         | 0      |            0 |       | 96e79218965eb72c92a549dd5a330112 | |  1402 |     2 | wei.liu@wenba100.com     |        |            0 |       | 72d1e186ab204c937ea48a3ff9f926fa | |  3385 |     2 | xiao.li@wenba100.com     | 0      |            0 |       | 263cad88649b39ed9fc95739c4f20edc | +-------+-------+--------------------------+--------+--------------+-------+----------------------------------+ 8 rows in set (0.25 sec)
mysql> ALTER IGNORE TABLE fudao_admin ADD UNIQUE `uq_user_name` (user_name); Query OK, 13530 rows affected, 1 warning (0.44 sec) Records: 13530  Duplicates: 11  Warnings: 1
mysql> select aid,count(aid) as total ,email,tel_no,account_type,exten,passwd  from fudao_admin    group by user_name having total> 1; Empty set (0.08 sec)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!