Keys
- Primary key (PK)
- A field (column) or group of fields that is used to identify the row uniquely
- PK is UNIQUE and NOT NULL
- Foreign key (FK)
- A field that uniquely identifies a record in another table
- Refers to the PK of the other table
- Table with the FK: referencing table / child table
- Table with the PK: referenced table / parent table
- A table can have multiple foreign keys
- FK and the referenced PK must MATCH!
- By defining a field as FK, each record in the column must have a reference in the parent table
-
PK can be NULL!
-
Field constraints
- NOT NULL
- UNIQUE
- PRIMARY KEY (not null + unique)
- CHECK: check a condition when you insert or update a value
- REFERENCES: values of the column must exist in another column in another table. Used for FK constraints