Glossary

Foreign Key

A foreign key is a database constraint that guarantees referential integrity between tables. A column in a child table may only contain values that exist in the parent table. The database will reject any insert or update that would violate this relationship.

Declaration

CREATE TABLE orders (
  id INT PRIMARY KEY,
  user_id INT,
  FOREIGN KEY (user_id) REFERENCES users(id)
    ON DELETE CASCADE
    ON UPDATE RESTRICT
);

ON DELETE / ON UPDATE strategies

Performance

MySQL/InnoDB automatically indexes FK columns. On large tables, FK validation on every insert adds ~5–10% overhead.