是的,MySQL允许在具有唯一约束的列中使用多个null.
CREATE TABLE table1 (x INT NULL UNIQUE);
INSERT table1 VALUES (1);
INSERT table1 VALUES (1); -- Duplicate entry '1' for key 'x'
INSERT table1 VALUES (NULL);
INSERT table1 VALUES (NULL);
SELECT * FROM table1;
结果:
x
NULL
NULL
1
例如,This is not true for all databases. SQL Server 2005及更高版本只允许在具有唯一约束的列中使用一个空值.