简体   繁体   中英

How to create UNIQUE key in mysql with BLANK value?

I have a mysql table users .

A column named Email contains NULL value.

I'm not able to create a unique key on email . It is showing an error saying duplicate value '' .

That's because you have multiple records on the email column with the value empty: ''

If you use InnoDB you can have multiple NULL values, but you can not have multiple empty values '' .

Try to clean the empty values with UPDATE users SET email = NULL WHERE email = '' and then create the unique key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM