HomeInterview QuestionsSql, Database Design, Keys

What is the difference between a primary key and a foreign key?

🟢 Easy Conceptual Junior level
1 Times asked
Aug 2026 Last seen
Aug 2026 First seen

💡 Model Answer

A primary key is a column or set of columns that uniquely identifies each row in a table. It must contain unique values and cannot be NULL. It enforces entity integrity and is often indexed for fast lookup. A foreign key, on the other hand, is a column or set of columns that references the primary key of another table, establishing a relationship between tables. It enforces referential integrity, ensuring that the value in the foreign key column matches a value in the referenced primary key or is NULL. While a primary key is internal to a table, a foreign key links tables together. In practice, a table can have only one primary key but multiple foreign keys, each pointing to different parent tables.

Sign in to unlock the rest of this answer

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500