Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 105/ 160
06. Database Design, Normalization & Semi-Structured SQL

Third Normal Form (3NF): Eliminating Transitive Dependencies

Remove transitive dependencies so non-keys depend only on keys.

IntermediateTransitive Dependency · 3NF3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Each fact should live in one place. If a column is really about something other than the row's key, move it to that thing's table.

Think of it like…

Writing a student's school address on every one of their exam papers. When the school moves, you have to correct every paper, and one missed paper means two "true" addresses. Store the address once, with the school.

Where you’ve seen it

orders(order_id, customer_id, customer_name, customer_city, amount): name and city depend on customer_id, not on order_id. Split it into orders(order_id, customer_id, amount) and customers(customer_id, name, city), and a city change touches one row.

Words you’ll hear

Functional dependency
A → B: knowing A determines B (customer_id determines customer_city).
Transitive dependency
Key → X → Y, where X isn't a key, so Y depends on the key only through X.
Update anomaly
The same fact stored in many rows gets changed in some but not others.
Denormalisation
Deliberately duplicating data for read performance, usually in analytics.

Visual diagram

Loading interactive diagram

Theory & example queries

Spotting a transitive dependency

For each non-key column, ask: "Is this a fact about the key, or about another column?" In orders, amount is a fact about the order; customer_city is a fact about the customer, which the order only refers to. That makes it transitive: order_id → customer_id → customer_city.

A well-known summary of the normal forms: every non-key column must depend on the key, the whole key (2NF), and nothing but the key (3NF). Typical 3NF violations are a zip code next to its city, a product's category name next to category_id, or an employee's department name next to department_id.

The splitQuery example
1Input dataStart from the source rows or state that the statement sees.
customers
3 rows
customers sample rows
idnameemailcity
1Mayamaya@example.comPune
2Raviravi@example.comDelhi
3Noornoor@example.comMumbai
orders
3 rows
orders sample rows
idcustomer_idstatusamountcoupon_code
1011paid249NULL
1022paid120WELCOME10
1031shipped89.5NULL
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1CREATE TABLE customers (2  id bigint PRIMARY KEY,3  name text,4  city text5);67CREATE TABLE orders (8  id bigint PRIMARY KEY,9  customer_id bigint REFERENCES customers (id),10  amount numeric11);
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Choose the target

Identify the table or database object the statement will modify.

1/11
3OutputInspect the representative rows, affected-row count, plan, or command status.
Normalized tables created
CREATE TABLE CREATE TABLE

Note: Representative PostgreSQL command tags; both table names must be unused.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

Key takeaway: If a column describes something other than the key, it belongs to that something's table.

Anomalies, and when to denormalise

Without 3NF you get three classic anomalies. Update: the city is stored on every order, so changes must hit every row. Insert: you can't record a new customer's city until they order. Delete: removing a customer's last order loses their details.

3NF is the normal target for transactional (OLTP) databases. Analytics warehouses often denormalise on purpose (star schemas, wide tables) because reads dominate and the data is loaded in controlled batches. Denormalise as a decision, not by accident.

Reading it backQuery example
1Input dataStart from the source rows or state that the statement sees.
customers
3 rows
customers sample rows
idnameemailcity
1Mayamaya@example.comPune
2Raviravi@example.comDelhi
3Noornoor@example.comMumbai
orders
3 rows
orders sample rows
idcustomer_idstatusamountcoupon_code
1011paid249NULL
1022paid120WELCOME10
1031shipped89.5NULL
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  o.id,3  o.amount,4  c.city5FROM6  orders o7  JOIN customers c ON c.id = o.customer_id;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/7
3OutputInspect the representative rows, affected-row count, plan, or command status.
Orders with customer city3 sample rows
Orders with customer city
idamountcity
5012499Pune
502899Delhi
5031750Pune

Note: Representative order and customer sample; the join retrieves city without storing it in orders.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

The join replaces the duplicated column.

Key takeaway: Normalise transactional data; denormalise analytics deliberately.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Analysis

Confirm the key

Identify the table's primary key and check it's already in 2NF: no column depends on just part of a composite key.

Focus at this step

PRIMARY KEY (order_id)

What to watch at this step
Prerequisite
2NF
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

A table is in Third Normal Form (3NF) when it's in 2NF and no non-key column depends on another non-key column. In other words, every non-key column describes the key directly, not something else in the row. A dependency like order_id → customer_id → customer_city is *transitive*, and 3NF moves it into its own table.

Why it matters: Transitive dependencies store the same fact in many rows, so updates, inserts and deletes go wrong: change a customer's city and you must update every order row, or the data contradicts itself. Normalisation questions are standard in backend and database interviews.

When to reach for it

  • Designing the schema of a transactional application
  • Reviewing a table that repeats the same value across many rows
  • Explaining update, insert and delete anomalies

When to avoid or be careful

  • Copying descriptive columns (names, cities) into every child table
  • Normalising analytics tables so far that every report needs ten joins
  • Storing derived values (order totals) without a plan to keep them in sync

2NF vs 3NF vs denormalised

2NF
Best for: A step on the way: no partial dependencies on a composite key

Strengths: Removes one class of duplication.

Watch out: Transitive dependencies can still duplicate facts.

3NF
Best for: Transactional application databases

Strengths: Each fact is stored once, so updates are simple and consistent.

Watch out: Reads need joins.

Denormalised (star schema, wide tables)
Best for: Analytics and reporting

Strengths: Fast reads with few joins.

Watch out: Duplicated data must be kept in sync by the loading process.

Interview signals & numbers to know

When this topic comes up

  • “Normalise this table”
  • “What is a transitive dependency?”
  • The same value repeated on many rows
  • Update, insert and delete anomalies
  • “When would you denormalise?”

Benchmarks & rules of thumb

1NF -
atomic values, no repeating groups
2NF -
no partial dependency on part of the key
3NF -
no dependency between non-key columns

Common mistakes & follow-ups

Common interview mistakes

  • Calling a table normalised because it has a primary key, while it still repeats customer details on every order.
  • Confusing 2NF (partial dependency on a composite key) with 3NF (dependency between non-key columns).
  • Normalising without moving the data carefully, so conflicting values for the same customer are silently lost.

Likely interviewer follow-ups

  • What's the difference between 2NF and 3NF?
  • What is BCNF, and when is a table in 3NF but not BCNF?
  • When would you deliberately denormalise, and what do you have to manage?
Interview tip: Use one concrete table (orders with customer_city), name the dependency chain, show the split, and list the three anomalies it fixes. A worked example beats reciting definitions.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Third Normal Form (3NF): Eliminating Transitive Dependencies with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
Second Normal Form (2NF): Eliminating Partial Dependencies
Next topic
Boyce-Codd Normal Form (BCNF) & Higher Normal Forms