UNIQUE NULL Behavior
UNIQUE NULL Behavior is a SQL statement in the Constraints category. Database-specific behavior of UNIQUE constraints with NULL values varies significantly across databases. The syntax is MySQL: multiple NULLs allowed. SQL Server: one NULL allowed (legacy). PostgreSQL: multiple NULLs allowed.. It returns null behavior per DB. A typical example: CREATE TABLE users (email VARCHAR(255) UNIQUE); -- MySQL: Multiple NULLs allowed INSERT INTO users (email) VALUES (NULL); -- OK (row 1) INSERT INTO users (email) VALUES (NULL); -- OK (row 2) -- SQL Server (legacy): Only one NULL allowed INSERT INTO users (email) VALUES (NULL); -- OK INSERT INTO users (email) VALUES (NULL); -- ERROR! -- PostgreSQL: Multiple NULLs allowed (SQL standard) INSERT INTO users (email) VALUES (NULL); -- OK… A close relative is PRIMARY KEY, which a column or set of columns that uniquely identifies each row. Only one PK per table. Automatically creates a unique index. A close relative is FOREIGN KEY, which ensures referential integrity: values in this column must exist in the referenced parent table.