- Error number
- 2601
- Severity
- 14 (user-correctable error)
- State
- 1
- Product
- Microsoft SQL Server Database Engine
- Versions
- All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
- Category
- Constraint & Integrity
- Last reviewed
- 23 October 2026
On this page
What it means
Error 2601 means an INSERT or UPDATE tried to store a key value that already exists in a column covered by a unique index, so SQL Server rejected the statement.
A unique index created with CREATE UNIQUE INDEX allows each key value only once. When a statement would add a second row with the same key, SQL Server stops the statement, rolls back its changes and raises 2601. The message names the table, the index and the duplicate value in brackets; for a multi-column index the brackets list every key column in index order, for example (1, SQL101), and a NULL appears as (<NULL>).
Severity 14 is a normal, catchable error about the data you sent, not a server fault. A PRIMARY KEY or UNIQUE constraint raises the sister error 2627 instead, even though it is also enforced by a unique index. If the duplicates are already in the table when you try to create the index, you get error 1505 (the CREATE UNIQUE INDEX statement terminated) rather than 2601.
Common causes
- The same row is written twice: a retried request, a double submit or a load script that is run again.
- An UPDATE changes the indexed column to a value another row already holds.
- An INSERT ... SELECT or bulk load whose source contains the same key more than once, or keys that already exist in the target.
- A unique index on a nullable column: SQL Server treats NULL as a value here, so a second row with NULL is a duplicate.
- Two sessions check for the value at the same moment, both find nothing, and both insert.
Diagnose it
Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.
Which columns does the index cover, and is it filtered?
SELECT i.name AS index_name, i.is_unique, i.has_filter, i.filter_definition,
c.name AS column_name, ic.key_ordinal
FROM sys.indexes AS i
JOIN sys.index_columns AS ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
WHERE i.name = N'UX_Users_Email'
AND i.object_id = OBJECT_ID(N'dbo.Users')
ORDER BY ic.key_ordinal; The key columns in order. With several columns, a row is a duplicate only when all of them match. has_filter = 1 means only rows that pass the filter are checked.
Find the row that already holds the value
SELECT *
FROM dbo.Users
WHERE email = N'sara@example.com'; -- the duplicate key value from the message The existing row. Compare it with the row you were writing to decide whether to skip, update or reject the new data.
Find duplicates in a source before loading it
-- Keys repeated inside the source
SELECT email, COUNT(*) AS copies
FROM dbo.StagingUsers
GROUP BY email
HAVING COUNT(*) > 1;
-- Keys that already exist in the target
SELECT s.email
FROM dbo.StagingUsers AS s
WHERE EXISTS (SELECT 1 FROM dbo.Users AS u WHERE u.email = s.email); Any row returned by either query would raise 2601 when loaded.
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Insert only when the value is not there yet
Changes dataRight for retries and re-runs. The UPDLOCK, HOLDLOCK hints stop two sessions from passing the check at the same time; keep the index as the final safety net and still handle 2601 in your code.
BEGIN TRANSACTION;
IF NOT EXISTS (SELECT 1 FROM dbo.Users WITH (UPDLOCK, HOLDLOCK) WHERE email = N'sara@example.com')
INSERT INTO dbo.Users (email) VALUES (N'sara@example.com');
COMMIT TRANSACTION;
Update the existing row instead (upsert)
Changes dataWhen an existing value should refresh the row rather than fail, update first and insert only if no row was updated.
BEGIN TRANSACTION;
UPDATE dbo.Users WITH (UPDLOCK, SERIALIZABLE)
SET display_name = N'Sara K'
WHERE email = N'sara@example.com';
IF @@ROWCOUNT = 0
INSERT INTO dbo.Users (email, display_name) VALUES (N'sara@example.com', N'Sara K');
COMMIT TRANSACTION;
De-duplicate the source before loading
Changes dataKeep one row per key with ROW_NUMBER() and skip keys the target already has. Agree with the data owner which copy should win; this keeps the most recently loaded one.
INSERT INTO dbo.Users (email)
SELECT email
FROM (
SELECT email,
ROW_NUMBER() OVER (PARTITION BY email ORDER BY loaded_at DESC) AS rn
FROM dbo.StagingUsers
) AS s
WHERE s.rn = 1
AND NOT EXISTS (SELECT 1 FROM dbo.Users AS u WHERE u.email = s.email);
Allow many NULLs with a filtered unique index
Changes schemaIf the column is optional and only real values must be unique, replace the index with a filtered one that ignores NULL. Rebuilding an index on a large table takes time and locks, so schedule it.
DROP INDEX UX_Users_Phone ON dbo.Users;
CREATE UNIQUE INDEX UX_Users_Phone
ON dbo.Users (phone)
WHERE phone IS NOT NULL;
Skip duplicates with IGNORE_DUP_KEY (only when losing them is acceptable)
Changes schemaA unique index created with IGNORE_DUP_KEY = ON discards duplicate rows from an INSERT and keeps the rest, printing Duplicate key was ignored. instead of failing. The discarded rows are gone without an error, so use it only for data where that is genuinely fine (tags, lookup lists). It does not apply to UPDATE.
CREATE UNIQUE INDEX UX_Tags_tag
ON dbo.Tags (tag)
WITH (IGNORE_DUP_KEY = ON);
Examples
Inserting a value that is already in the index
CREATE TABLE dbo.Users (
id INT IDENTITY(1,1) CONSTRAINT PK_Users PRIMARY KEY,
email NVARCHAR(256) NOT NULL
);
CREATE UNIQUE INDEX UX_Users_Email ON dbo.Users (email);
INSERT INTO dbo.Users (email) VALUES (N'sara@example.com');
INSERT INTO dbo.Users (email) VALUES (N'sara@example.com'); -- already exists
Msg 2601, Level 14, State 1, Line 8 Cannot insert duplicate key row in object 'dbo.Users' with unique index 'UX_Users_Email'. The duplicate key value is (sara@example.com). The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
An UPDATE that collides with another row
CREATE TABLE dbo.Users (
id INT IDENTITY(1,1) CONSTRAINT PK_Users PRIMARY KEY,
email NVARCHAR(256) NOT NULL
);
CREATE UNIQUE INDEX UX_Users_Email ON dbo.Users (email);
INSERT INTO dbo.Users (email) VALUES (N'sara@example.com'), (N'ali@example.com');
UPDATE dbo.Users SET email = N'sara@example.com' WHERE id = 2;
Msg 2601, Level 14, State 1, Line 8 Cannot insert duplicate key row in object 'dbo.Users' with unique index 'UX_Users_Email'. The duplicate key value is (sara@example.com). The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
INSERT ... SELECT from a source that repeats a key
CREATE TABLE dbo.Users (
id INT IDENTITY(1,1) CONSTRAINT PK_Users PRIMARY KEY,
email NVARCHAR(256) NOT NULL
);
CREATE UNIQUE INDEX UX_Users_Email ON dbo.Users (email);
CREATE TABLE dbo.StagingUsers (email NVARCHAR(256));
INSERT INTO dbo.StagingUsers (email) VALUES (N'omar@example.com'), (N'omar@example.com');
INSERT INTO dbo.Users (email)
SELECT email FROM dbo.StagingUsers; -- the whole statement fails, no rows are loaded
Msg 2601, Level 14, State 1, Line 10 Cannot insert duplicate key row in object 'dbo.Users' with unique index 'UX_Users_Email'. The duplicate key value is (omar@example.com). The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
How to prevent it
Let the database generate surrogate keys (IDENTITY or a SEQUENCE), make writes that may run twice idempotent, and de-duplicate staging data before it reaches the target. Decide early whether an optional column should be unique only when filled in, and use a filtered index if so.
Keep the unique index even when the application checks first: under concurrency only the index is reliable. Catch 2601 and 2627 together in your error handling and turn them into a clear "already exists" message. For how unique indexes and constraints relate, see the constraints guide.
Common questions
Why does a second NULL raise error 2601?
In a SQL Server unique index NULL counts as a value, so only one row may hold it. Use a filtered unique index with WHERE column IS NOT NULL if many rows may leave the column empty.
What is the difference between error 2601 and 2627?
Error 2601 comes from a unique index created with CREATE UNIQUE INDEX; error 2627 from a PRIMARY KEY or UNIQUE constraint. The cause and the fixes are the same, so handle both numbers together.
Does error 2601 insert the other rows of a multi-row INSERT?
No. The whole statement is rolled back, so none of its rows are stored. Only an index created with IGNORE_DUP_KEY = ON keeps the non-duplicate rows.
Learn more on CodeWithSQL
Official documentation
- Create unique indexes (Microsoft Learn)
- CREATE INDEX (Transact-SQL)
- Database Engine events and errors 2000 to 2999
Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.