Second normal form
- SQL course
- Intermediate
- Lesson 90/115
- 4 min
Learn second normal form (2NF).
2NF
2NF is in 1NF with no partial dependency. In a composite key, each column must depend on the whole key.
-- order_items(order_id, product, qty, product_name)
-- product_name yalnız product'a bağlı → 2NF ihlaliMove product_name to a products table.
2NF — details
2NF removes partial dependencies. A column depending on part of a composite key is moved to its own table.
For example, in a table keyed by (order_id, product_id), the product name depends only on product_id, so it moves to the products table.
Practice 2NF
Move product_name to a products table to reach 2NF.
Starter code
-- normalize to 2NF
CREATE TABLESample solution
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100)
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Second normal form: match the terms
| Term | Meaning |
|---|---|
2NF |
partial dependency |
composite key |
multi |
full key |
all |
separate |
move |
2 2NF dependency
2NF: depends on the ____ as a whole
2NF: depends on the key as a whole
Explanation: In 2NF every non-key column depends on the whole key.
3 What does 2NF remove?
- Partial dependency Correct answer
- Repetition
- NULLs
- The index
Explanation: 2NF removes partial dependencies.