HomeInterview QuestionsWhat is the difference between a primary key and a…

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

🟢 Easy Conceptual Junior level
1Times asked
Aug 2026Last seen
Aug 2026First 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.

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