SQL Keyword ADD CONSTRAINT

The ADD CONSTRAINT keyword can be used to create a new constraint on an existing table, using the ALTER TABLE statement.

The below SQL adds a primary key constraint, based on a single column.

ALTER TABLE customers
ADD CONSTRAINT PK_Customer PRIMARY KEY (customer_id);

The below SQL adds a primary key constraint, based on multiple columns (namely id and name).

ALTER TABLE customers
ADD CONSTRAINT PK_Customer PRIMARY KEY (customer_id, customer_name);

Related Links