QUESTION 1 OF 15

What constraints does a primary key enforce?

Reveal the answer and explore the explanation.

01
EasyCore

What constraints does a primary key enforce?

Answer
Answer

Uniquely identifies a table row and cannot be null.

Practical example

Assign every test attempt a unique ID.

SQLRelated concept example
SELECT topic_slug, AVG(score) AS average_score
FROM test_attempts
WHERE user_id = $1
GROUP BY topic_slug
ORDER BY average_score;

Bind the user ID as a parameter and verify ownership server-side.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As