关于Mysql唯一索引的学习

关于Mysql唯一索引的学习记录

Mysql版本:5.7+

在创建表后,建立唯一索引

  UNIQUE KEY `i_operator_collector_shipperId` (`operator`,`collector`,`shipper_id`,`collection_type`)

竟然可以查询出来多条记录,说明没有触发唯一索引

 

 

最终通过查找资料发现

Mysql allows multiple NULLs in an unique constraint.In your serial_number column replace NULL with a value and the constraint is triggered,see:

a UNIQUE index permits multiple NULL values for columns that can

contain NULL

Make the column NOT NULL and use '' which is empty.

posted @ 2022-06-30 15:51  温柔的星空,让你感动  阅读(24)  评论(0编辑  收藏  举报