Home › Interview Questions › What is a primary key and a foreign key in relatio…

What is a primary key and a foreign key in relational databases, and why are they important?

🟢 Easy Conceptual Fresher level
1Times asked
Oct 2026Last seen
Oct 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, non‑NULL values and is often indexed to speed up lookups. A foreign key is a column (or set) that references the primary key of another table, establishing a relationship between the two tables. The foreign key enforces referential integrity: it ensures that a value in the child table corresponds to an existing row in the parent table, preventing orphaned records. Together, primary and foreign keys provide a structured way to model real‑world relationships, enable efficient joins, and maintain data consistency across the database. They also allow the database engine to enforce constraints automatically, reducing application‑level validation logic and improving data quality.

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