All technological notes.
Constraint
Type of constraints
Column Constraints: constrains the data in a column to adhere to certain conditions.
Table Constraints: applied to the entire table rather than to an individual column.
SERIALPrimary Key
SERIAL
Syntax:
CREATE TABLE tb_name(
tb_id SERIAL PRIMARY KEY
);
REERENCESForeign Key
Referencing table / Child table
Referenced table / Parent table
REERENCES
Syntax:
CREATE TABLE tb_name(
tb_id SERIAL PRIMARY KEY,
f_key INTEGER REFERENCES ref_tb_name(pk_col)
);
NOT NULLEnsure that all values
Syntax:
CREATE TABLE tb_name(
col_name DATATYPE NOT NULL
);
UNIQUEEnsure that all values in a column are different.
Syntax:
CREATE TABLE tb_name(
col_name DATATYPE UNIQUE
);
CHECKEnsure that all values in a column satify certain conditions.
Allow to create more customized constraints that adhere to a certain condition.
Syntax:
CREATE TABLE tb_name(
col_name datatype CHECK(col_name > num)
)
EXCLUSION