How would you model a many-to-many relationship between students and courses?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Create students and courses tables plus an enrollment table containing foreign keys to both. Add a primary key or unique constraint on the student-course pair if only one enrollment is permitted. Attributes such as enrollment date, grade, or status belong to the relationship record. If repeat enrollment is allowed, include a term or enrollment identifier in the model instead of forcing false uniqueness. Define deletion and history rules explicitly. A comma-separated list of course IDs in the student row makes integrity checks, queries, and updates unnecessarily difficult.
Related Questions in Database
DBA Interview Questions
Intermediate level • 743 views
MS-SQL Server developer interview questions
Advanced level • 263 views
MySQL management interview questions
Beginner level • 169 views
Why can a replica return stale data immediately after a successful write?
Medium level • 4 views
How do a primary key, foreign key, and unique constraint serve different purposes?
Easy level • 3 views