Foreign Keys in SQL — a practical guide to SQL foreign key with clear examples you can reuse in real projects.
SQL Tutorial Series (8/100). Prefer one article? Read the complete SQL tutorial.
Short description
Foreign keys enforce relationships and enable cascading rules.
Foreign key
CREATE TABLE orders (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);