coderz.py

Keep Coding Keep Cheering!

First Normal Form (1NF)

SQL Views

Let’s look at the first normal form in detail from the previous lecture where we saw a brief overview of the normal forms.

First Normal Form (1NF) is the first level of normalization in database design. It ensures that the data in a table is organized in a way that avoids redundancy and anomalies. The two rules of 1NF are:

  • Atomic Values: Only atomic or indivisible values should be present in each column. For instance, the 1NF is violated when a column that stores a list of phone numbers separated by commas has multiple values.
  • No Repeating Groups: Only one value should be present in each column. No repeating data sets or multiple values in the same column are acceptable. For example, a column that stores multiple addresses for a single customer violates 1NF because it contains repeating groups of data.
Example: Atomic Value Violation
IDNameAgeContact
1Ramesh321234567890,21314152
2Mukesh408978654372
3Sumit459450012002
4Kaushik258912342503
Customer Table

The above table violates the 1NF rule as the contact value for first row isn’t atomic. To solve such an issue we will create another table, i.e

IDContact
11234567890
121314152
28978654372
39450012002
48912342503
Contact Table
Example: Repeating Groups
IDNameAgeCity1City2Country
1Ramesh32HyderabadDelhiIndia
2Mukesh40New YorkUSA
3Sumit45MuscatOman
4Kaushik25KolkataIndia
Customer Table

Because the City column is repeated twice, this table is not in the first normal form, as you can see in the current table. Whether the person stays in two cities or not, this table always allots disc space for two cities.

To eliminate the repeating columns and bring the table to the first normal form, separate the table into two tables. Create one of the tables with the repeating columns as shown below:

IDNameAge
1Ramesh32
2Mukesh40
3Sumit45
4Kaushik25
Customer Table
IDCityCountry
1HyderabadIndia
1DelhiIndia
2New YorkUSA
3MuscatOman
4KolkataIndia
Address Table

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Advertisement