T-SQL Tutorial

Msg 1779 Level 16 - Table already has a primary key defined on it


Transact sql error message Msg 1779 Level 16 - Table already has a primary key defined on it - means that exists an primary key defined in the table.

Msg 1779 Level 16 Example:

USE model;
GO
CREATE TABLE students( id INT NOT NULL PRIMARY KEY, first_name CHAR(50), last_name CHAR(50),
gender CHAR(1), city CHAR(100), country CHAR(50), dep_id INT);
GO

Invalid alter table:

USE model;
GO
ALTER TABLE students ADD PRIMARY KEY (id) ;
GO

Message
Msg 1779, Level 16, State 0, Line 1
Table 'students' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

Other error messages: