| Lesson 4 | One-to-one relationships, part 1 |
| Objective | Define 1:1 relationships and show when and how to implement them. |
A one-to-one (1:1) relationship links at most one instance of entity A with at most one instance of entity B—and vice versa. True 1:1 is less common than 1:N, but it’s valuable for:
Key characteristics
UNIQUE).NOT NULL.
Choose one based on ownership, optionality, and access patterns.
-- A exists before B; B shares A's key
CREATE TABLE A (
A_ID INT PRIMARY KEY,
... -- base attributes
);
CREATE TABLE B (
B_ID INT PRIMARY KEY,
... -- segmented/sensitive attributes
CONSTRAINT fk_b_a
FOREIGN KEY (B_ID) REFERENCES A(A_ID)
);
Pros: simplest uniqueness guarantee; fewer indexes. Cons: strict lifecycle coupling.
CREATE TABLE A ( A_ID INT PRIMARY KEY, ... ); CREATE TABLE B ( B_ID INT PRIMARY KEY, A_ID INT UNIQUE, -- ensures at most one B per A ..., CONSTRAINT fk_b_a UNIQUE (A_ID), CONSTRAINT fk_b_a_ref FOREIGN KEY (A_ID) REFERENCES A(A_ID) );
Pros: allows B to have its own surrogate key; flexible migrations. Cons: requires both UNIQUE and FK constraints.
Where to put the FK?
NOT NULL.User(UserID) ↔ UserAuth(UserID, PasswordHash, MFA...) (privacy, audit).
Connectivity indicates one or many per side; 1:1 means “one” on both sides. The cardinality (actual counts) can vary by instance, but constraints enforce the upper bound. Optionality (0 or 1) is modeled via nullable FKs; mandatory (1) via NOT NULL plus referential integrity.
Be careful not to model a disguised 1:N as 1:1. If, over time, multiple B rows per A appear, your 1:1 will be violated—check business rules and sample data.
The next lesson continues with additional 1:1 design nuances and edge cases.