Categories: DBMS

Second Normal Form(2NF)

What is 2NF?

The second step in Normalization is 2NF. A table must meet two requirements to be in the second normal form:

  • The relation must be in the 1NF.
  • In the second normal form, all non-key attributes are entirely functionally dependent on the primary key

Let’s see, what we mean by dependency.

What are Database Dependencies, and Why Do They Matter?

A constraint that outlines the connection between attributes is a database dependency. This occurs when data from one database table uniquely determines data from another stored in a different database table. Since database dependencies serve as the fundamental building blocks for database normalization, it is crucial to understand what they are.

The process of effectively organizing data in a database is called normalization. Database normalization aims to achieve two main goals. First, redundant data must be removed, and second, data dependencies must be made logically. By doing this, you can ensure that the data is stored logically and decrease the space a database uses.

What is Partial Dependency?

A table’s attribute may be functionally dependent on only a portion of a composite primary key rather than the entire key, which is known as partial dependency. It happens when a non-key attribute is dependent only on a portion of the columns for the primary key.

Note: If the proper subset of the candidate key determines non-prime attribute, it is called partial dependency.

For example, let’s consider a table of customer orders:

Order_IDCustomer_IDCustomer_NameOrder_DateOrder_Total
1A0110Ranbeer Singh12-03-222300
1A0281Niharika Yadav01-01-23499
1B2110Ranbeer Singh13-02-221599
Order Table

In this table, the Order_ID and Customer_ID combination serves as the primary key. But the Customer_Name attribute only needs the Customer ID; it doesn’t need the entire primary key. This is an example of partial dependency.

We must normalize the table to make sure that every non-key attribute depends on the entire primary key to eliminate partial dependency. To achieve this, we could divide the table into two tables:

Order_IDCustomer_IDOrder_DateOrder_Total
1A011012-03-222300
1A028101-01-23499
Order Table
Customer_IDCustomer_Name
10Ranbeer Singh
81Niharika Yadav
Customer Table

The Customer Name attribute now only depends on the Customer ID and does not depend on any other elements of the primary key. By doing so, the table will be in Second Normal Form (2NF).

Note: also read about Normalization of Database

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Generate Parenthesis | Intuition + Code | Recursion Tree | Backtracking | Java

Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…

2 months ago

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago