0
0
SQLquery~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What is a one-to-one relationship in database design?
A one-to-one relationship means each record in one table matches exactly one record in another table, like a person having one passport.
Click to reveal answer
intermediate
How do you enforce a one-to-one relationship between two tables in SQL?
Use a unique foreign key in one table that references the primary key of the other table, ensuring each key appears only once.
Click to reveal answer
intermediate
Why might you split data into two tables with a one-to-one relationship?
To separate optional or sensitive data, improve organization, or optimize performance by loading only needed data.
Click to reveal answer
beginner
Which SQL constraint ensures that a foreign key is unique in a one-to-one relationship?
The UNIQUE constraint on the foreign key column ensures no duplicates, enforcing one-to-one mapping.
Click to reveal answer
intermediate
Example: How to create two tables with a one-to-one relationship between 'Person' and 'Passport'?
Create 'Person' with primary key 'person_id'. Create 'Passport' with 'passport_id' as primary key and 'person_id' as unique foreign key referencing 'Person'.
Click to reveal answer
What does a one-to-one relationship mean in databases?
AMany records in one table match many records in another table
BOne record in a table matches many records in another table
CEach record in one table matches exactly one record in another table
DNo relationship between tables
Which SQL constraint is essential to enforce a one-to-one relationship?
AUNIQUE constraint on the foreign key
BDEFAULT constraint
CCHECK constraint
DNOT NULL constraint
In a one-to-one relationship, where is the foreign key usually placed?
AIn the table with optional or additional data
BIn both tables
CIn the table with the primary key only
DNowhere, foreign keys are not used
Why split data into two tables with a one-to-one relationship?
ATo duplicate data
BTo avoid using foreign keys
CTo make queries slower
DTo separate optional or sensitive data
Which SQL statement correctly creates a one-to-one relationship?
ACREATE TABLE Passport (passport_id INT PRIMARY KEY, person_id INT, FOREIGN KEY (person_id) REFERENCES Person(person_id));
BCREATE TABLE Passport (passport_id INT PRIMARY KEY, person_id INT UNIQUE, FOREIGN KEY (person_id) REFERENCES Person(person_id));
CCREATE TABLE Passport (passport_id INT PRIMARY KEY, person_id INT);
DCREATE TABLE Passport (passport_id INT PRIMARY KEY, person_id INT NOT NULL);
Explain how to design a one-to-one relationship between two tables in SQL.
Think about keys and uniqueness to link tables.
You got /4 concepts.
    Why would you use a one-to-one relationship instead of combining all data in one table?
    Consider reasons for splitting data logically.
    You got /4 concepts.