0
0
SQLquery~10 mins

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

Choose your learning style9 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.