Unique constraint that allows empty values in MySQL Unique constraint that allows empty values in MySQL mysql mysql

Unique constraint that allows empty values in MySQL


Yes, you can do this. See the MySQL reference (version 5.5).

A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL.


Yes, if you make the product code column nullable (not declared with NOT NULL), the unique key will allow multiple rows with NULL product codes.


MySQL still allows for multiple rows to have a value of NULL in a unique column.