What constraints does a primary key enforce?
Reveal the answer and explore the explanation.
01EasyCoreWhat constraints does a primary key enforce?
Answer
EasyCore
What constraints does a primary key enforce?
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 ↗