On Transact SQL language the Msg 2627 Level 14 - Violation of PRIMARY KEY constraint means that you cannot insert duplicate key in object.
Msg 2627 Level 14 Example:
We have the table TEST:
USE model;
GO
CREATE TABLE TEST(
ID INT NOT NULL PRIMARY KEY,
NAME VARCHAR(10) NOT NULL,
BIRTHDAY date );
GO
ID | NAME | BIRTHDAY |
---|---|---|
1 | Tom | 1982-07-15 |
Invalid insert:
USE model;
GO
INSERT INTO TEST(id, name, birthday) VALUES (1, 'Tom','1982-07-15');
GO
Message |
---|
Msg 2627, Level 14, State 1, Line 1 |
Violation of PRIMARY KEY constraint 'PK__TEST__3214EC27C70092B2'. Cannot insert duplicate key in object 'dbo.TEST'. The duplicate key value is (1). The statement has been terminated. |
Correct insert:
USE model;
GO
INSERT INTO TEST(id, name, birthday) VALUES (2, 'Tom','1982-07-15');
GO
Message |
---|
(1 row(s) affected) |
Other error messages:
- Specified scale is invalid
- Foreign key references invalid column in referenced table
- Table already has a primary key defined on it
- Column name does not exist in the target table or view
- Column names in each table must be unique
- There is already an object named in the database
- Could not find stored procedure