SyntaxStudy
Sign Up
MySQL Second Normal Form (2NF)
MySQL Intermediate 4 min read

Second Normal Form (2NF)

Second Normal Form

2NF: must be in 1NF, and every non-key column must depend on the entire primary key (no partial dependencies). Relevant when the PK is composite.

Example
-- Violates 2NF: order_items with composite PK (order_id, product_id)
-- product_name depends only on product_id, not the full PK

-- Fix: separate products table
CREATE TABLE products (
  id INT PRIMARY KEY,
  name VARCHAR(255),
  price DECIMAL(10,2)
);

CREATE TABLE order_items (
  order_id INT,
  product_id INT,
  quantity INT,
  PRIMARY KEY (order_id, product_id)
);
Pro Tip

2NF issues only arise with composite primary keys.