Recall & Review
beginner
What is a many-to-many relationship in databases?
It is a relationship where multiple records in one table relate to multiple records in another table. For example, students can enroll in many courses, and courses can have many students.
Click to reveal answer
beginner
Why do we use a junction table in many-to-many relationships?
A junction table breaks down a many-to-many relationship into two one-to-many relationships. It stores pairs of related record IDs from the two tables, making the relationship manageable and queryable.
Click to reveal answer
intermediate
What columns does a junction table usually have?
It usually has at least two columns, each holding a foreign key that references the primary key of one of the related tables. Sometimes it also has its own primary key or additional data.
Click to reveal answer
intermediate
Write a simple SQL query to find all courses a student with ID 1 is enrolled in, using a junction table named Enrollment.
SELECT Courses.* FROM Courses JOIN Enrollment ON Courses.CourseID = Enrollment.CourseID WHERE Enrollment.StudentID = 1;
Click to reveal answer
intermediate
How does a junction table improve data integrity in many-to-many relationships?
By using foreign keys, it ensures that only valid records from the related tables can be linked. This prevents invalid or orphaned relationships and keeps data consistent.
Click to reveal answer
What does a junction table do in a many-to-many relationship?
✗ Incorrect
A junction table stores pairs of IDs from the two related tables to represent many-to-many relationships.
Which of these is true about foreign keys in a junction table?
✗ Incorrect
Foreign keys in a junction table reference primary keys in the related tables to maintain valid links.
If a student can enroll in many courses and a course can have many students, what kind of relationship is this?
✗ Incorrect
This is a many-to-many relationship because multiple students can enroll in multiple courses.
Which SQL clause is commonly used to connect tables through a junction table?
✗ Incorrect
JOIN is used to combine rows from two or more tables based on related columns.
What is a common name for a table that links two tables in a many-to-many relationship?
✗ Incorrect
A junction table links two tables in a many-to-many relationship.
Explain how a many-to-many relationship is implemented using a junction table.
Think about how two tables connect through a third table storing pairs of IDs.
You got /4 concepts.
Describe how you would write a SQL query to find all related records using a junction table.
Consider joining the main tables through the junction table on matching IDs.
You got /4 concepts.