Cannot add multiple PRIMARY KEY constraints to table ‘%1!’.

Error Message:
Msg 8110, Level 16, State 0, Line 1
Cannot add multiple PRIMARY KEY constraints to table ‘%1!’.

Severity level:
16.

Description:
This error message appears when you try to declare more than one PRIMARY KEY constraint in the same CREATE TABLE statement.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Error of the Severity level 16 are generated by the user and can be fixed by the SQL Server user. In this case the error can only be prevented, when the CREATE TABLE statement modified so, that just one PRIMARY KEY constraint exists.

Versions:
All versions of SQL Server.

Example(s):
USE tempDB
GO
CREATE TABLE #t
(
 c1 INT PRIMARY KEY
 , c2 INT PRIMARY KEY
)
GO
DROP TABLE #t

Remarks:
In the above example we’ll create the temporary table #t. In the CREATE TABLE block we try to create a PRIMARY KEY constraint on column c1. Direct below we also try to define a second PRIMARY KEY constraint on column c2. This raises the error. Instead of the second PK constraint, you can create an UNIQUE constraint or an UNIQUE index on c2.




Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |