Home›Learn›SQL›Foreign Key
SQL Master CourseBeginner Friendly

Foreign Key

Learn how foreign keys create relationships between tables.

📘 Chapter 38 / 51⏱️ 8–10 Min Read🎯 Beginner Friendly
Course Progress75%

Course Progress

75%

38 / 51 chapters

📖

Theory

Understand the concept step by step

A foreign key is a column or set of columns that references a key in another table. It is commonly used to establish relationships between related tables and maintain referential integrity.
💻

Example

See how the concept works in SQL

SQL
CREATE TABLE orders (
  id INT PRIMARY KEY,
  user_id INT,
  FOREIGN KEY (user_id)
    REFERENCES users(id)
);
📤

Output

Understand what the query produces

user_id references the id column in the users table.

📝

Practice

Test your understanding

Create orders and users tables connected using a foreign key.

❓

MCQs

Check your SQL knowledge

What is the main concept covered in Foreign Key?

A.Creates a relationship between tables
B.Sorts records
C.Deletes records
D.Creates duplicate rows
💼

Interview Questions

Prepare for SQL interviews

1

Interview Question

What is a foreign key?

2

Interview Question

Why are foreign keys used?

3

Interview Question

What is referential integrity?