Recall & Review
beginner
What is a one-to-many relationship in database design?
It is a relationship where one record in a table (the 'one' side) can be related to many records in another table (the 'many' side). For example, one customer can have many orders.
Click to reveal answer
beginner
How do you represent a one-to-many relationship in SQL tables?
By adding a foreign key column in the 'many' side table that references the primary key of the 'one' side table.
Click to reveal answer
beginner
Why do we use foreign keys in one-to-many relationships?
Foreign keys link records between tables, ensuring data integrity by making sure the 'many' side records relate to a valid 'one' side record.
Click to reveal answer
beginner
Example: If you have tables 'Authors' and 'Books', which table should have the foreign key?
The 'Books' table should have a foreign key column referencing the 'Authors' table because one author can write many books.
Click to reveal answer
intermediate
What happens if you try to insert a record in the 'many' side table with a foreign key value that does not exist in the 'one' side table?
The database will reject the insert to maintain data integrity, because the foreign key must reference an existing record in the 'one' side table.
Click to reveal answer
In a one-to-many relationship, where is the foreign key placed?
✗ Incorrect
The foreign key is placed in the table on the 'many' side to link back to the 'one' side.
Which SQL constraint ensures that the foreign key value must exist in the referenced table?
✗ Incorrect
The FOREIGN KEY constraint enforces that the value must exist in the referenced table.
If one author can write many books, what kind of relationship is this?
✗ Incorrect
One author writing many books is a classic example of a one-to-many relationship.
What is the main purpose of using a foreign key in one-to-many relationships?
✗ Incorrect
Foreign keys link tables and ensure data integrity by enforcing valid relationships.
Which of these is a valid example of a one-to-many relationship?
✗ Incorrect
One customer placing many orders is a one-to-many relationship.
Explain how to design a one-to-many relationship between two tables in a database.
Think about which table holds the foreign key and why.
You got /3 concepts.
Describe a real-life example of a one-to-many relationship and how it would be represented in SQL tables.
Consider something like customers and orders or authors and books.
You got /3 concepts.