thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Commonly confused · Data & Analytics

Primary Key vs Foreign Key: What's the Difference?

A primary key uniquely identifies each row in its own table and cannot be null. A foreign key is a column in one table that references the primary key of another table, creating a relationship and enforcing referential integrity.

Primary Key

Full definition
vs

Foreign Key

Full definition
Primary KeyForeign Key
PurposeUniquely identify a rowLink to a row in another table
UniquenessMust be uniqueCan repeat (many rows reference one parent)
Nulls allowedNoYes, unless constrained
Per tableOne (may span multiple columns as a composite key)Many
EnforcesEntity integrityReferential integrity
ExampleCustomerID in Customers tableCustomerID in Orders table
Remember it

The primary key is who you are; the foreign key is who you belong to.

Exam tip

Expect ERD questions identifying keys in one-to-many relationships, where the foreign key sits on the many side. Also know a surrogate key versus a natural key.

Tested on

More Data & Analytics look-alikes