create table test3
(
id int PRIMARY KEY,
id2 int
);
create unique index ndx_id2 on test3 (id2);
For the purposes of unique indices, all NULL
values are considered to different from all other NULL
values and are thus unique. This is one of the two possible interpretations of the SQL-92 standard (the language in the standard is ambiguous) and is the interpretation followed by PostgreSQL, MySQL, Firebird, and Oracle.
Informix and Microsoft SQL Server follow the other interpretation of the standard.
INSERT INTO test3(id, id2) VALUES (1, null);
INSERT INTO test3(id, id2) VALUES (2, null);
Second INSERT returns
A duplicate value cannot be inserted into a unique index. [ Table name = test3,Constraint name = ndx_id2 ]
Error in SQL Server but successfully adds record to another DBMS, Sqlite for example.
How to allow in the field with a unique constraint to enter a lot of null values in SQL Server?