Bird
Raised Fist0
SQLquery~10 mins

Second Normal Form (2NF) in SQL - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Second Normal Form (2NF)
Start with 1NF table
↓
Check for composite primary key?
Yes↓
Identify partial dependencies
Yes No↓
Remove partial dependencies
↓
Table in 2NF
↓
End
Start with a table in 1NF, check if it has a composite key. If yes, find and remove partial dependencies to achieve 2NF.
Execution Sample
SQL
CREATE TABLE Orders (
  OrderID INT,
  ProductID INT,
  ProductName VARCHAR(50),
  Quantity INT,
  PRIMARY KEY (OrderID, ProductID)
);
This table has a composite primary key (OrderID, ProductID) but ProductName depends only on ProductID, showing a partial dependency.
Execution Table
StepActionCheck/ConditionResult/Next Step
1Start with Orders tableTable in 1NF with composite key (OrderID, ProductID)Proceed to check dependencies
2Check if ProductName depends on whole keyProductName depends only on ProductID (partial dependency)Partial dependency found
3Remove partial dependency by creating Products tableMove ProductID and ProductName to Products tableOrders table now has OrderID, ProductID, Quantity
4Check Orders table for partial dependenciesNo partial dependencies remainOrders table is now in 2NF
5Check Products tablePrimary key ProductID, no partial dependenciesProducts table is in 2NF
6EndBoth tables in 2NFNormalization complete
💡 No partial dependencies remain; all non-key attributes depend on the whole primary key.
Variable Tracker
TableInitial ColumnsAfter Step 3Final Columns
OrdersOrderID, ProductID, ProductName, QuantityOrderID, ProductID, QuantityOrderID, ProductID, Quantity
ProductsN/AProductID, ProductNameProductID, ProductName
Key Moments - 2 Insights
Why do we need to remove partial dependencies?
Partial dependencies cause redundancy and anomalies. Removing them ensures each non-key attribute depends on the whole key, as shown in execution_table step 2 and 3.
What if the primary key is not composite?
If the primary key is a single column, 2NF is automatically satisfied because partial dependency cannot exist, as implied in execution_table step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the partial dependency identified?
AStep 1
BStep 4
CStep 2
DStep 5
💡 Hint
Check the 'Check/Condition' column for 'partial dependency found' in execution_table.
According to variable_tracker, which table contains ProductName after normalization?
AOrders
BProducts
CBoth Orders and Products
DNeither table
💡 Hint
Look at the 'Final Columns' for each table in variable_tracker.
If the Orders table had only OrderID as primary key, what would change in the execution flow?
ANo partial dependencies could exist, so 2NF is already satisfied
BPartial dependencies would still need removal
CComposite key would be created automatically
DProductName would depend on OrderID only
💡 Hint
Refer to key_moments about primary key composition and 2NF.
Concept Snapshot
Second Normal Form (2NF):
- Table must be in 1NF first.
- Remove partial dependencies on composite keys.
- Every non-key attribute depends on the whole primary key.
- If primary key is single column, 2NF is automatic.
- Helps reduce redundancy and update anomalies.
Full Transcript
Second Normal Form (2NF) is a database normalization step that builds on First Normal Form (1NF). It applies when a table has a composite primary key, meaning the key is made of more than one column. In such cases, some columns might depend only on part of the key, called partial dependencies. These cause data duplication and problems when updating. To fix this, we split the table to remove partial dependencies, ensuring every non-key column depends on the entire key. If the primary key is a single column, 2NF is already satisfied. The example Orders table has a composite key (OrderID, ProductID) but ProductName depends only on ProductID. We move ProductName to a new Products table. After this, both tables are in 2NF, reducing redundancy and improving data integrity.

Practice

(1/5)
1. Which of the following best describes the Second Normal Form (2NF) in database design?
easy
A. It removes partial dependencies on a part of a composite key.
B. It eliminates all transitive dependencies.
C. It requires that all columns be atomic.
D. It allows duplicate rows in a table.

Solution

  1. Step 1: Understand 2NF definition

    2NF requires that no non-key attribute depends on only part of a composite primary key.
  2. Step 2: Compare options with 2NF

    'It removes partial dependencies on a part of a composite key.' correctly states this. 'It eliminates all transitive dependencies.' describes 3NF. 'It requires that all columns be atomic.' describes 1NF, and 'It allows duplicate rows in a table.' is incorrect.
  3. Final Answer:

    It removes partial dependencies on a part of a composite key. -> Option A
  4. Quick Check:

    2NF = Remove partial dependencies [OK]
Hint: 2NF fixes partial dependencies on composite keys [OK]
Common Mistakes:
  • Confusing 2NF with 3NF
  • Thinking 2NF removes all duplicates
  • Believing 2NF requires atomic columns
2. Which SQL table design violates Second Normal Form (2NF)?
CREATE TABLE Orders (OrderID INT, ProductID INT, ProductName VARCHAR(50), Quantity INT, PRIMARY KEY (OrderID, ProductID));
easy
A. OrderID and ProductID together form the primary key.
B. Quantity depends on both OrderID and ProductID.
C. ProductName depends only on ProductID, not the whole key.
D. The table has a composite primary key.

Solution

  1. Step 1: Identify dependencies in the table

    ProductName depends only on ProductID, which is part of the composite key (OrderID, ProductID).
  2. Step 2: Check 2NF violation

    Since ProductName depends on part of the key, this violates 2NF which forbids partial dependencies.
  3. Final Answer:

    ProductName depends only on ProductID, not the whole key. -> Option C
  4. Quick Check:

    Partial dependency = 2NF violation [OK]
Hint: Check if non-key columns depend on part of composite key [OK]
Common Mistakes:
  • Assuming composite key alone ensures 2NF
  • Ignoring partial dependencies
  • Confusing primary key with foreign key
3. Given the table below:
StudentCourses(StudentID, CourseID, StudentName, CourseName, Grade)
Which of the following correctly identifies the partial dependencies violating 2NF?
medium
A. Grade depends only on StudentID.
B. StudentName depends only on StudentID, and CourseName depends only on CourseID.
C. StudentName depends on both StudentID and CourseID.
D. CourseName depends on Grade.

Solution

  1. Step 1: Understand composite key and dependencies

    The composite key is (StudentID, CourseID). StudentName depends only on StudentID, CourseName only on CourseID.
  2. Step 2: Check 2NF compliance

    2NF requires no partial dependencies. StudentName depending only on StudentID and CourseName only on CourseID are partial dependencies on parts of the composite key, violating 2NF.
  3. Final Answer:

    StudentName depends only on StudentID, and CourseName depends only on CourseID. -> Option B
  4. Quick Check:

    Partial dependencies exist if 2NF not met [OK]
Hint: In 2NF, no partial dependency on composite key parts [OK]
Common Mistakes:
  • Thinking Grade depends only on StudentID
  • Assuming CourseName depends on Grade
  • Ignoring partial dependencies
4. You have this table:
CREATE TABLE Enrollment (StudentID INT, CourseID INT, StudentName VARCHAR(50), CourseName VARCHAR(50), PRIMARY KEY (StudentID, CourseID));
Which change fixes the 2NF violation?
medium
A. Keep the table as is; 2NF is not violated.
B. Add StudentName and CourseName as part of the primary key.
C. Remove the composite key and use a single primary key.
D. Split into three tables: Students(StudentID, StudentName), Courses(CourseID, CourseName), and Enrollment(StudentID, CourseID).

Solution

  1. Step 1: Identify 2NF violation

    StudentName depends only on StudentID, CourseName only on CourseID, causing partial dependencies.
  2. Step 2: Fix by splitting tables

    Splitting into Students(StudentID, StudentName), Courses(CourseID, CourseName), and Enrollment(StudentID, CourseID) removes partial dependencies, achieving 2NF.
  3. Final Answer:

    Split into three tables: Students(StudentID, StudentName), Courses(CourseID, CourseName), and Enrollment(StudentID, CourseID). -> Option D
  4. Quick Check:

    Split tables to remove partial dependencies [OK]
Hint: Split tables to fix partial dependencies [OK]
Common Mistakes:
  • Adding non-key columns to primary key
  • Removing composite key incorrectly
  • Ignoring partial dependencies
5. A table has columns: OrderID, ProductID, ProductName, Quantity, SupplierName with composite primary key (OrderID, ProductID). SupplierName depends only on ProductID. How should you redesign the table to achieve 2NF?
hard
A. Create two tables: Orders(OrderID, ProductID, Quantity) and Products(ProductID, ProductName, SupplierName).
B. Add SupplierName to the primary key.
C. Remove ProductID from the primary key.
D. Keep all columns in one table; 2NF is already satisfied.

Solution

  1. Step 1: Identify partial dependency

    SupplierName depends only on ProductID, part of the composite key, violating 2NF.
  2. Step 2: Normalize by splitting tables

    Separate Products table with ProductID, ProductName, SupplierName removes partial dependency, Orders table keeps OrderID, ProductID, Quantity.
  3. Final Answer:

    Create two tables: Orders(OrderID, ProductID, Quantity) and Products(ProductID, ProductName, SupplierName). -> Option A
  4. Quick Check:

    Split tables to remove partial dependencies [OK]
Hint: Move partial dependency columns to separate table [OK]
Common Mistakes:
  • Adding non-key columns to primary key
  • Removing part of composite key incorrectly
  • Assuming 2NF allows partial dependencies
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard