Second Normal Form (2NF): Eliminating Partial Dependencies
Remove partial dependencies on composite keys to reach 2NF.
In plain words
If a column only depends on part of a combined key, move it to the table where that part is the whole key.
Think of it like…
A class attendance sheet keyed by (student, date) that also lists each student's home address on every line. The address depends only on the student, not on the date, so it belongs on the student's record, written once.
Where you’ve seen it
enrolments(student_id, course_id, grade, course_title, instructor): course_title and instructor depend only on course_id. Renaming a course means updating every enrolment row. Splitting off courses(course_id, title, instructor) stores each course's details once.
Words you’ll hear
- Composite key
- A primary key made of two or more columns.
- Partial dependency
- A non-key column determined by only part of the composite key.
- Full dependency
- A non-key column that needs every key column to be determined, such as quantity.
- 2NF vs 3NF
- 2NF removes dependencies on part of the key; 3NF removes dependencies on non-key columns.
Visual diagram
Theory & example queries
Spotting partial dependencies
For each non-key column in a table with a composite key, ask: "Could I determine this from just one of the key columns?" In order_items, quantity needs both the order and the product. product_name needs only the product, so it's a partial dependency.
A table whose primary key is a single column can't have a partial dependency, so if it's in 1NF it's automatically in 2NF. That makes 2NF mostly a concern for junction tables, enrolment and line-item tables.
| id | order_id | product_id | qty | price |
|---|---|---|---|---|
| 1 | 101 | 42 | 2 | 49.5 |
| 2 | 101 | 84 | 1 | 150 |
| 3 | 102 | 42 | 1 | 49.5 |
| id | name | price | category | stock |
|---|---|---|---|---|
| 42 | SQL Notebook | 49.5 | books | 18 |
| 84 | Mechanical Keyboard | 150 | hardware | 5 |
| 11 | Query Mug | 12.99 | gifts | 33 |
CREATE TABLE products ( id bigint PRIMARY KEY, name text NOT NULL);CREATE TABLE order_items ( order_id bigint REFERENCES orders (id), product_id bigint REFERENCES products (id), quantity int NOT NULL, PRIMARY KEY (order_id, product_id));PostgreSQL is the lesson baseline unless noted otherwise.
Identify the table or database object the statement will modify.
Successful schema creation
Note: Command tags are representative of PostgreSQL; exact client output varies by dialect.
Key takeaway: Ask of each column: does it need the whole key?
A subtle case: current vs historical values
The product's current price depends only on product_id and belongs in products. But the price the customer actually paid on that order is a fact about the order line, and must not change when the catalogue price changes later. That's a full dependency, so unit_price legitimately stays on order_items.
So normalising isn't just mechanically moving columns. Decide whether a column is the current attribute of the thing (move it) or a snapshot recorded at the time of the event (keep it).
order_items (order_id, product_id, quantity, unit_price_paid) with products (id, name, current_price): the two prices mean different things.
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Confirm 1NF and find composite keys
Only tables with multi-column primary keys can violate 2NF, so start with junction and line-item tables.
PRIMARY KEY (order_id, product_id)
When to use it & trade-offs
What it is
A table is in Second Normal Form (2NF) when it's in 1NF and every non-key column depends on the *whole* primary key, not just part of it. It only matters for tables with a composite key: in order_items(order_id, product_id, quantity, product_name), product_name depends only on product_id, which is a partial dependency, so it belongs in the products table.
Why it matters: Partial dependencies copy the same fact (a product's name or price) onto every row that mentions it, so updates must touch many rows and can leave them disagreeing. It's a standard step in normalisation questions, usually asked right after 1NF.
When to reach for it
- Line-item, enrolment and junction tables
- Explaining normalisation step by step
- Removing duplicated product or course details
When to avoid or be careful
- Copying descriptive columns of one part of the key onto every row
- Moving historical snapshot values that must not change
- Worrying about 2NF on tables with a single-column key
1NF vs 2NF vs 3NF
Strengths: Data can be queried and indexed properly.
Watch out: Facts can still be duplicated across rows.
Strengths: No column depends on only part of the key.
Watch out: Dependencies between non-key columns can remain.
Strengths: Every non-key column depends on the key and nothing else.
Watch out: More tables and joins.
Interview signals & numbers to know
When this topic comes up
- “What is 2NF?”
- “What's a partial dependency?”
- Composite primary keys
- Product names repeated on order lines
- Normalise this schema
Benchmarks & rules of thumb
- 2+
- key columns needed for a partial dependency
- 1NF
- prerequisite for 2NF
- 3NF
- the next step: no transitive dependencies
Common mistakes & follow-ups
Common interview mistakes
- Confusing a partial dependency (on part of the key) with a transitive dependency (on another non-key column).
- Moving unit_price_paid to products and rewriting history whenever the price changes.
- Saying a table with a single-column key violates 2NF.
Likely interviewer follow-ups
- Why can't a table with a single-column primary key violate 2NF?
- What's the difference between a partial and a transitive dependency?
- Should an order line store the product price? Why?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Second Normal Form (2NF): Eliminating Partial Dependencies with hands-on SQL practice and interview Q&A.