Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. Primary key vs foreign key?

SQL · Keys, Schema & CTEs

Primary key vs foreign key?

Easysql-37
primary keyforeign keyrelationships

Question

Primary key vs foreign key?

Solution

Primary key: identifies a row in its own table.

Foreign key: references a key in another table.

Example:

customers
---------
id ← primary key

orders
------
customer_id ← foreign key

It establishes a relationship between tables.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext