One-to-One
ELI5 — The Vibe Check
One-to-One is a relationship where one row in Table A corresponds to exactly one row in Table B. Like a user and their profile — one user, one profile. You could put it all in one table but sometimes you split for organization or performance.
Real Talk
A one-to-one relationship between two entities means each record in Table A is related to exactly one record in Table B and vice versa. Implemented with a foreign key and UNIQUE constraint. Often used to split a table for optional data, security, or performance (e.g., users and user_settings).
Show Me The Code
CREATE TABLE user_profiles (
user_id INT PRIMARY KEY REFERENCES users(id),
bio TEXT,
avatar_url TEXT
);
When You'll Hear This
"The user and user_profile tables have a one-to-one relationship." / "One-to-one is often better merged into one table unless there's a reason to split."
Related Terms
ERD (Entity Relationship Diagram)
An ERD is a visual map of your database — boxes for tables, lines showing how they connect.
Foreign Key
A foreign key is how you link two tables together. If an 'orders' table has a 'user_id' column pointing to the 'users' table, that is a foreign key.
Many-to-Many
Many-to-Many means rows on both sides can relate to many rows on the other side. Students can enroll in many courses, and courses can have many students.
One-to-Many
One-to-Many means one row in Table A can relate to many rows in Table B. One user can have many orders. One post can have many comments.