Title - Constraints in SQL Tags - sqlconstraints
Constraints can be used to tell the database to reject inserted data that doesn’t adhere to a certain condition.
Example:
CREATE TABLE celebs ( id INTEGER PRIMARY KEY, name TEXT UNIQUE, date_of_birth TEXT NOT NULL, date_of_death TEXT DEFAULT ‘Not Applicable’ );
Attempting to insert a new row with an identifcal value to an existing row will result in a constraint violation that prevents insertion of the new row. PRIMARY KEY columns can be used to uniquely identify the row.
UNIQUE columns have a different value for every row. This is similar to PRIMARY KEY. Except, a table can have many different UNIQUE rows.
NOT NULL columns must have a value.
DEFAULT