Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Jul 16, 2024
Easy

First Normal Form (1NF) in DBMS

Author Gaurish Anand
0 upvote
Table of contents
Leveraging ChatGPT - GenAI as a Microsoft Data Expert
23 Jul, 2024 @ 01:30 PM
Speaker
Prerita Agarwal
Data Specialist @

1 NF in DBMS is a part of normalization. Normalization is used to remove the redundancy and inconsistent dependence in the database. Anomalies in insertion, deletion, and update can be caused by relation redundancy. 

First Normal Form (1NF) in DBMS

To normalize a dataset, we break down this large dataset into different smaller datasets depending upon the relationships among tables. 

There are various types of normal forms. Some of them are 

  1. First Normal Form (1NF)
  2. Second Normal Form (2NF)
  3. Third Normal Form (3NF)
  4. Boyce Codd Normal Form (BCNF

Here, we will be discussing the first normal form.

What is First Normal Form?

A relation (table) in a DBMS is in First Normal Form (1NF) if all its attributes contain atomic values (single, indivisible data) and there are no repeating groups within the table. Additionally, each attribute must have a unique name.

Rules of 1st NF in DBMS

For a table to be in 1NF, it should follow these rules: 

  1. The table only contains composite or single-valued attributes.
  2. Every Attribute/Column should have a different name.
  3. There should be no difference in which order data is stored.
  4. The domain of the attribute should not change.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Example of 1NF in DBMS

Because of the multi-valued attribute STUD_PHONE, the relation STUDENT is not in 1NF

Example 1

STUDENT table: 

STUD_IDSTUD_NAMESTUD_PHONESTUD_CITY
1Harsh

727282638X,

906473823X

Delhi
Shivam981161425XBanglore
Pranav

739037238X,

858983030X

Mumbai

The above table decomposed into 1NF will like this: 

STUD_IDSTUD_NAMESTUD_PHONESTUD_CITY
1Harsh727282638XDelhi
1Harsh906473823XDelhi
Shivam981161425XBanglore
Pranav739037238XMumbai
Pranav858983030XMumbai

Example 2

Here's an example of a table violating 1NF:

Customer IDCustomer NameCourses Enrolled
1AliceMath, Science, English
2BobProgramming, History

drive_spreadsheetExport to Sheets

This table violates 1NF because of the "Courses Enrolled" column. It contains multiple values (course names) separated by commas, which breaks the rule of atomic values in a cell.

Fixing the Table for 1NF

Here's how to fix the table to comply with 1NF:

Create a Separate Table for Courses:

We'll create a new table named "Enrollments" to link customers with their enrolled courses.

Enrollments Table:

Enrollment ID (Primary Key)Customer ID (Foreign Key)Course Name
11Math
21Science
31English
42Programming
52History

Original Customer Table (Modified):

Customer ID (Primary Key)Customer Name
1Alice
2Bob

Frequently Asked Questions

What are the anomalies in 1NF in DBMS?

1NF itself doesn't have anomalies (data inconsistencies). However, tables that violate 1NF principles can lead to insertion, deletion, and update anomalies during data manipulation.

Why is 1NF important?

1NF is the foundation for a well-structured database. It ensures data integrity by eliminating redundancy and promoting efficient data manipulation, retrieval, and modification.

What is the significance of 1NF in database design?

1NF serves as the first step in database normalization. By enforcing atomic values and eliminating repeating groups, it creates a solid base for further normalization processes that optimize database design for efficiency and accuracy.

How do you convert data to the first normal form?

Identify and eliminate repeating groups within a table. If data needs to be repeated for certain rows, create separate tables and link them with appropriate relationships. Additionally, ensure each cell contains a single, indivisible value.

Does 1NF have a primary key?

1NF doesn't mandate a primary key. However, establishing a primary key for each table is good practice and often implemented during database normalization processes beyond 1NF.

Conclusion

We learned about the First Normal Form (1NF) in DBMS in this article. First Normal Form (1NF) serves as the essential building block for a well-organized and efficient database. By enforcing atomic values and eliminating repeating groups, 1NF promotes data integrity and simplifies data manipulation.

Since SQL-related questions are frequently asked in interviews, we recommend you practice Top 100 SQL problems on Code360. 

Also, check out - Anomalies In DBMS.

Are you planning to ace the interviews of reputed product-based companies like Amazon, Google, Microsoft, and more? Attempt our Online Mock Test Series on Code360 now!