---
title: "SQL Server UNIQUE constraint with duplicate NULLs"  
description: "SQL Server UNIQUE constraint with duplicate NULLs"  
author: "Revati S Misra"  
published: 2023-04-27  
updated: 2025-01-08  
canonical: https://www.mindstick.com/forum/158047/sql-server-unique-constraint-with-duplicate-nulls  
category: "mssql server"  
tags: ["database", "sql server", "sql"]  
reading_time: 2 minutes  

---

# SQL Server UNIQUE constraint with duplicate NULLs

[SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) [UNIQUE constraint](https://www.mindstick.com/forum/159036/how-can-i-create-a-unique-constraint-that-also-allows-nulls) with [duplicate](https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server) NULLs

## Replies

### Reply by Khushi Singh

In Data Manipulation, the `UNIQUE` [constraint](https://www.mindstick.com/articles/434/constraint-in-sql-server) in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) 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 has `UNIQUE` constraint. This behavior is that SQL Server operates `NULL` as the unknown value and the two `NULLs` are not equal.

**Behavior of** `UNIQUE` **Constraint with** `NULLs`

- If a column has `UNIQUE` constraint, multiple `NULL` values can be stored in this column because SQL Server does not support uniqueness constraint for `NULL`.
- Nonetheless, any value in that column cannot be `NULL` if other similar values already exist or are present in the database.

## Example:

```plaintext
-- Create a table with a UNIQUE constraint
CREATE TABLE Employee (
   EmployeeID INT,
   Email NVARCHAR(100) UNIQUE
);
-- Insert values
INSERT INTO Employee (EmployeeID, Email) VALUES (1, 'john@example.com'); -- Valid
INSERT INTO Employee (EmployeeID, Email) VALUES (2, 'jane@example.com'); -- Valid
INSERT INTO Employee (EmployeeID, Email) VALUES (3, NULL);               -- Valid
INSERT INTO Employee (EmployeeID, Email) VALUES (4, NULL);               -- Valid (allows duplicate NULLs)

-- Attempt to insert a duplicate non-NULL value
INSERT INTO Employee (EmployeeID, Email) VALUES (5, 'john@example.com'); -- Error: Violation of UNIQUE constraint
```

Hope it helps!!\
\

\


---

Original Source: https://www.mindstick.com/forum/158047/sql-server-unique-constraint-with-duplicate-nulls

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
