Candidate Keys

tags: #sql/constraints

We can specify a secondary candidate key using the UNIQUE constraint.

A candidate key is a column or set of columns that can uniquely identify each row in a table.

By default, a table can have only one primary key, but it can have multiple candidate keys defined using the UNIQUE constraint.

CREATE TABLE employees (
    emp_id INT NOT NULL PRIMARY KEY,
    emp_email VARCHAR(255) NOT NULL UNIQUE,
    emp_phone VARCHAR(20) NOT NULL UNIQUE,
    ...
);
Powered by Forestry.md