0
0
SQLquery~20 mins

Second Normal Form (2NF) in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
2NF Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Identify partial dependency violation in 2NF

Consider a table Orders with columns: OrderID, ProductID, ProductName, Quantity. The primary key is a composite key of (OrderID, ProductID).

Which column violates the Second Normal Form (2NF) by having a partial dependency?

SQL
CREATE TABLE Orders (
  OrderID INT,
  ProductID INT,
  ProductName VARCHAR(100),
  Quantity INT,
  PRIMARY KEY (OrderID, ProductID)
);
AProductName
BQuantity
COrderID
DProductID
Attempts:
2 left
💡 Hint

Think about which column depends only on part of the composite key.

🧠 Conceptual
intermediate
1:30remaining
Understanding 2NF requirements

Which of the following statements correctly describes the requirement for a table to be in Second Normal Form (2NF)?

AIt must have a single-column primary key.
BIt must have no transitive dependency on any non-key attribute.
CIt must have no partial dependency on any candidate key.
DIt must have no duplicate rows.
Attempts:
2 left
💡 Hint

2NF focuses on dependencies related to composite keys.

schema
advanced
2:30remaining
Decompose table to achieve 2NF

Given the table StudentCourses with columns StudentID, CourseID, StudentName, CourseName, and composite primary key (StudentID, CourseID), which decomposition correctly achieves 2NF?

ACreate two tables: <code>Students(StudentID, StudentName)</code> and <code>Courses(CourseID, CourseName)</code> plus <code>Enrollments(StudentID, CourseID)</code>
BCreate one table with all columns and remove the primary key
CCreate two tables: <code>Students(StudentID, StudentName)</code> and <code>Enrollments(StudentID, CourseID, CourseName)</code>
DCreate one table with all columns and add a unique constraint on <code>StudentName</code>
Attempts:
2 left
💡 Hint

Think about separating attributes that depend only on part of the key.

🔧 Debug
advanced
2:00remaining
Find the error causing 2NF violation

Given this table definition:

CREATE TABLE Sales (
  SaleID INT,
  ProductID INT,
  ProductDescription VARCHAR(255),
  Quantity INT,
  PRIMARY KEY (SaleID, ProductID)
);

Which problem causes this table to violate 2NF?

AQuantity depends on both SaleID and ProductID.
BProductDescription depends only on ProductID, a part of the composite key.
CSaleID is not unique.
DPrimary key should be a single column.
Attempts:
2 left
💡 Hint

Look for columns that depend on only part of the key.

optimization
expert
3:00remaining
Optimize table design to remove partial dependencies

You have a table OrderDetails with columns OrderID, ProductID, ProductPrice, OrderDate, and composite primary key (OrderID, ProductID).

Which design change best removes partial dependencies to achieve 2NF?

AMake ProductPrice part of the primary key
BKeep all columns in one table and add a unique constraint on ProductPrice
CRemove ProductPrice column from the table
DSplit into <code>Orders(OrderID, OrderDate)</code> and <code>OrderItems(OrderID, ProductID, ProductPrice)</code>
Attempts:
2 left
💡 Hint

Separate attributes that depend only on part of the key into their own table.