I Help You
Databases

Foreign Key

A foreign key is a column in one table that refers to the primary key of another table, creating a link between the two. For example, an orders table can have a customer_id column that points to the id in the customers table.

The database uses foreign keys to enforce referential integrity: it rejects values that do not exist in the referenced table, and can automatically restrict, cascade or set NULL when the referenced row is updated or deleted.

Example
CREATE TABLE orders (
  id          INT PRIMARY KEY,
  customer_id INT NOT NULL,
  total       DECIMAL(10, 2),
  FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE
);