SQL Server UNIQUE constraint with duplicate NULLs
SQL Server UNIQUE constraint with duplicate NULLs
304
27-Apr-2023
Updated on 08-Jan-2025
Khushi Singh
08-Jan-2025In Data Manipulation, the
UNIQUEconstraint in SQL Server will restrict the records such that no two records have similar values either in this column or in one or many other columns. Nonetheless, SQL Server permitting duplication of NULL in a column that hasUNIQUEconstraint. This behavior is that SQL Server operatesNULLas the unknown value and the twoNULLsare not equal.Behavior of
UNIQUEConstraint withNULLsUNIQUEconstraint, multipleNULLvalues can be stored in this column because SQL Server does not support uniqueness constraint forNULL.NULLif other similar values already exist or are present in the database.Example:
Hope it helps!!