Primary Key Constraint
SQL Primary Key Constraint
A SQL Primary Key constraint is a column or a combination of several columns that contain values that uniquely identify each row in the table.
A table can contain only one PRIMARY KEY constraint.
A primary key cannot exceed 16 columns and a total key length of 900 bytes.
All columns defined within a PRIMARY KEY constraint must be defined as NOT NULL.
If nullability is not specified, then all columns participating in a PRIMARY KEY constraint will be automatically set to NOT NULL.
Example 1
CREATE TABLE Test1 ( ID INT PRIMARY KEY, TITLE VARCHAR(250) NOT NULL, );
Example 2
CREATE TABLE Test2 ( ID INT, TITLE VARCHAR(250), DESCRIPTION VARCHAR(250), CONSTRAINT PK_TL2 PRIMARY KEY (ID, TITLE) );
Example 3
CREATE TABLE Test3 ( ID INT NOT NULL, TITLE VARCHAR(250) NOT NULL, ); ALTER TABLE Test3 ADD CONSTRAINT PKTest3_ID PRIMARY KEY (ID);