Problem Statement
What is the main purpose of a FOREIGN KEY constraint?
Explanation
A foreign key enforces referential integrity. Values in the child column must exist in the referenced parent key.
This prevents orphan records and maintains valid relationships as data changes.
Code Solution
SolutionRead Only
CREATE TABLE orders ( id BIGINT PRIMARY KEY, customer_id BIGINT REFERENCES customers(id) );
Practice Sets
This question appears in the following practice sets:
