What is a composite primary key and when should you use it?
This question assesses understanding of unique identification strategies when single-column keys are insufficient.
Why Interviewers Ask This
Real-world data often requires multiple attributes to uniquely identify a record. Interviewers want to know if you can design robust schemas that handle complex relationships correctly without creating redundancy.
How to Answer This Question
Define a composite key as using two or more columns to uniquely identify a row. Give examples like order items where order_id and product_id together form the key. Explain why a single column isn't enough in these scenarios.
Key Points to Cover
- Multiple columns for uniqueness
- Handles many-to-many relationships
- Prevents ambiguity
- Common in junction tables
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 instance, in an order_items table, neither the order ID nor the product ID alone is uniq…
Common Mistakes to Avoid
- Using it unnecessarily
- Forgetting foreign key implications
- Not explaining the 'why'
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.