A foreign key constraint links a column in one table to the primary key (or a unique key) of another table, enforcing referential integrity so that a value in the child table must correspond to an existing value in the parent table.
In a school database, the Students table has a Course_ID column with a foreign key referencing the Courses table's Course_ID, which guarantees a student can never be assigned to a course that doesn't actually exist.
CREATE TABLE courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(100)
);
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(50),
course_id INT,
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);A concise interview answer is
A foreign key constraint ties a column to the primary key of another table so the database enforces referential integrity -- you can't insert a child row pointing at a parent that doesn't exist. In a school database, a student's course_id would be a foreign key referencing the courses table, guaranteeing students are only ever assigned to real courses.
Last updated: 11 November 2026
Previous question: What is the difference between a primary key and a unique key?
Next question: What is the difference between NULL and zero in MySQL?