Error 2615

Severity Level 14

Message Text

Attempt to insert duplicate row in table '%.*s' with index '%.*s' in database '%.*s'. Could drop and recreate index with ignore duprow or allow duprow

Explanation

This error occurs when you attempt to insert a duplicate row into a table that has a clustered index. By default, tables with clustered indexes do not allow duplicate rows.

Action

You can change the clustered index to allow duplicate rows or you can delete duplicate rows.

To allow duplicate rows, create the clustered index with the allow_dup_row option. Duplicate rows can then be created using the insert or update statement, as shown here:

create clustered index idx_pubname
on publishers(pub_name) with ALLOW_DUP_ROW
go

Do not use this method if you have a unique index on any columns in the table. Unique indexes are only used on tables that do not allow duplicate rows.

To delete duplicate rows, you can create the clustered index with the ignore_dup_row option, as shown here:

create clustered index idx_pubname
ON publishers(pub_name) with IGNORE_DUP_ROW
go

Existing duplicate rows will be deleted when the index is created. Future attempts to enter a duplicate row with the INSERT or UPDATE statement are ignored and the INSERT or UPDATE is canceled. If the INSERT or UPDATE is part of a transaction, the remainder of the transaction will continue.

If the duplicate data is the result of invalid data, you can change or delete the duplicate data and rerun the transaction.

Note that the allow_dup_row and ignore_dup_row options are mutually exclusive. Using them in the same create index statement causes error 1916.

For more information about indexes, see the CREATE INDEX statement in the Microsoft SQL Server Transact-SQL Reference.