What is a composite primary key and when is it used?
This question tests understanding of identifying records using multiple columns. It evaluates design decisions for relationships.
Why Interviewers Ask This
Candidates must demonstrate they can handle complex entity relationships. Interviewers look for the ability to identify scenarios where a single column cannot uniquely identify a row. This shows maturity in database schema design.
How to Answer This Question
Define a composite primary key as using two or more columns together. Explain that it is necessary when no single column provides uniqueness. Give an example like a junction table linking orders and products.
Key Points to Cover
- Multiple columns for uniqueness
- Used when single key fails
- Common in many-to-many relationships
- Ensures row distinctness
Sample Answer
A composite primary key uses two or more columns together to uniquely identify each row when one column alone isn't sufficient. For example, in a table linking students to courses, neither student ID nor course ID is uni…
Common Mistakes to Avoid
- Thinking it's just multiple foreign keys
- Not providing a concrete example
- Ignoring the impact on indexing
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.