SQL Tutorial 0/85 lessons ~6 min read Lesson 20

    One-to-One Relationship

    A 1:1 relationship means each row in table A maps to exactly one row in table B.

    Course progress0%
    Focus
    6 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    A 1:1 relationship means each row in table A maps to exactly one row in table B. Common when you split rarely-used or sensitive columns into a sister table.

    Understanding the topic

    Core concepts to understand:

    • Implementation: profiles.user_id as both FK and UNIQUE.
    • Use cases: separating PII, optional details, or frequently-vs-rarely accessed data.
    • Could you put it in one table? Often yes — split when it earns its keep.
    • Performance: smaller hot table; cold data lives separately.
    • Cascade delete keeps the pair consistent.

    Syntax reference

    Visual workflow / architecture:

    bash
    users profiles
    ┌────┐ 1:1 UNIQUE ┌──────────┐
    │ id │ ─────────────▶│ user_id │ (UNIQUE FK)
    └────┘ │ bio, dob │
    └──────────┘

    Real-world use

    Many SaaS apps split users (auth) from profiles (PII), so security policies can differ.

    Best practices

    • Add UNIQUE on the FK in B to enforce 1:1.
    • Consider whether merging into one table is simpler.
    • Use CASCADE delete to keep the pair in sync.

    Hands-on exercise

    Interview preparation — practice these questions:

    • Q1. How do you enforce 1:1 in SQL?
    • Q2. When would you split a 1:1 vs keep in one table?
    • Q3. Do you need a FK for 1:1?
    • Q4. CASCADE behavior in 1:1.
    • Q5. Is 1:1 common in practice?
    Ready to mark this lesson complete?Track your journey across the entire course.