0
0
SQLquery~5 mins

One-to-many relationship design in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIn the table on the 'one' side
BIn the table on the 'many' side
CIn both tables
DNo foreign key is needed
Which SQL constraint ensures that the foreign key value must exist in the referenced table?
APRIMARY KEY
BUNIQUE
CFOREIGN KEY
DCHECK
If one author can write many books, what kind of relationship is this?
AOne-to-many
BOne-to-one
CMany-to-many
DNo relationship
What is the main purpose of using a foreign key in one-to-many relationships?
ATo speed up queries
BTo store duplicate data
CTo create indexes
DTo link tables and maintain data integrity
Which of these is a valid example of a one-to-many relationship?
AEach customer can place many orders
BEach book has many authors
CEach employee works in many departments
DEach student has one ID card
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.