- SQL Tutorial
- SQL - Home
- SQL - Overview
- SQL - RDBMS Concepts
- SQL - Databases
- SQL - Syntax
- SQL - Data Types
- SQL - Operators
- SQL - Expressions
- SQL Database
- SQL - Create Database
- SQL - Drop Database
- SQL - Select Database
- SQL - Rename Database
- SQL - Show Databases
- SQL - Backup Database
- SQL Table
- SQL - Create Table
- SQL - Show Tables
- SQL - Rename Table
- SQL - Truncate Table
- SQL - Clone Tables
- SQL - Temporary Tables
- SQL - Alter Tables
- SQL - Drop Table
- SQL - Delete Table
- SQL - Constraints
- SQL Queries
- SQL - Insert Query
- SQL - Select Query
- SQL - Select Into
- SQL - Insert Into Select
- SQL - Update Query
- SQL - Delete Query
- SQL - Sorting Results
- SQL Views
- SQL - Create Views
- SQL - Update Views
- SQL - Drop Views
- SQL - Rename Views
- SQL Operators and Clauses
- SQL - Where Clause
- SQL - Top Clause
- SQL - Distinct Clause
- SQL - Order By Clause
- SQL - Group By Clause
- SQL - Having Clause
- SQL - AND & OR
- SQL - BOOLEAN (BIT) Operator
- SQL - LIKE Operator
- SQL - IN Operator
- SQL - ANY, ALL Operators
- SQL - EXISTS Operator
- SQL - CASE
- SQL - NOT Operator
- SQL - NOT EQUAL
- SQL - IS NULL
- SQL - IS NOT NULL
- SQL - NOT NULL
- SQL - BETWEEN Operator
- SQL - UNION Operator
- SQL - UNION vs UNION ALL
- SQL - INTERSECT Operator
- SQL - EXCEPT Operator
- SQL - Aliases
- SQL Joins
- SQL - Using Joins
- SQL - Inner Join
- SQL - Left Join
- SQL - Right Join
- SQL - Cross Join
- SQL - Full Join
- SQL - Self Join
- SQL - Delete Join
- SQL - Update Join
- SQL - Left Join vs Right Join
- SQL - Union vs Join
- SQL Keys
- SQL - Unique Key
- SQL - Primary Key
- SQL - Foreign Key
- SQL - Composite Key
- SQL - Alternate Key
- SQL Indexes
- SQL - Indexes
- SQL - Create Index
- SQL - Drop Index
- SQL - Show Indexes
- SQL - Unique Index
- SQL - Clustered Index
- SQL - Non-Clustered Index
- Advanced SQL
- SQL - Wildcards
- SQL - Comments
- SQL - Injection
- SQL - Hosting
- SQL - Min & Max
- SQL - Null Functions
- SQL - Check Constraint
- SQL - Default Constraint
- SQL - Stored Procedures
- SQL - NULL Values
- SQL - Transactions
- SQL - Sub Queries
- SQL - Handling Duplicates
- SQL - Using Sequences
- SQL - Auto Increment
- SQL - Date & Time
- SQL - Cursors
- SQL - Common Table Expression
- SQL - Group By vs Order By
- SQL - IN vs EXISTS
- SQL - Database Tuning
- SQL Function Reference
- SQL - Date Functions
- SQL - String Functions
- SQL - Aggregate Functions
- SQL - Numeric Functions
- SQL - Text & Image Functions
- SQL - Statistical Functions
- SQL - Logical Functions
- SQL - Cursor Functions
- SQL - JSON Functions
- SQL - Conversion Functions
- SQL - Datatype Functions
- SQL Useful Resources
- SQL - Questions and Answers
- SQL - Quick Guide
- SQL - Useful Functions
- SQL - Useful Resources
- SQL - Discussion
First Normal Form (1NF)
Database normalization is the process of efficiently organizing data in a database to eliminate the redundant data from the database and ensuring data dependencies make sense. Various Normalization Forms are used to eliminate or reduce data redundancy in database tables.
What is First Normal Form (1NF)?
First Normal Form (1NF) sets the basic rules to organize the data in a database. A database is said to be in first normal form if it satisfies the following conditions −
Rule 1 (Atomic Values) − Every column of a table should contain only atomic values. An atomic value is a value that cannot be divided further.
Rule 2 (No Repeating Groups) − There are no repeating groups of data. This means a table should not contain repeating columns.
While designing your database tables, you must take care of atleast the First Normal Form compliance otherwise you will put yourself in a big problem during database operatoons.
Rule 1 - Atomic Values
Every column of a table should contain only atomic values. An atomic value is a value that cannot be divided further.
Consider the following CUSTOMERS table which is being used to store customers data −
ID | Name | Age | Salary | City | Country |
---|---|---|---|---|---|
1 | Ramesh | 32 | 2000.00 | Hyderabad, Delhi | India |
2 | Mukesh | 40 | 5000.00 | New York | USA |
3 | Sumit | 45 | 4500.00 | Muscat | Oman |
4 | Kaushik | 25 | 2500.00 | Kolkata | India |
This table is not in first normal form because the City column can contain multiple values. For example, the first row includes values "Hyderabad" and "Delhi."
Now to bring this table to first normal form, we have to consider the real problem where a customer can stay in different cities which could be in the same or different countries. So we split the table into two separate tables as below −
CUSTOMERS Table
ID | Name | Age | Salary |
---|---|---|---|
1 | Ramesh | 32 | 2000.00 |
2 | Mukesh | 40 | 5000.00 |
3 | Sumit | 45 | 4500.00 |
4 | Kaushik | 25 | 2500.00 |
CUSTOMERS_ADDRESS Table
ID | City | Country |
---|---|---|
1 | Hyderabad | India |
1 | Delhi | India |
2 | New York | USA |
3 | Muscat | Oman |
4 | Kolkata | India |
Rule 2 - No Repeating Groups
There are no repeating groups of data. This means a table should not contain repeating columns.
Consider the following CUSTOMERS table which is being used to store customers data −
ID | Name | Age | Salary | City1 | City2 | Country |
---|---|---|---|---|---|---|
1 | Ramesh | 32 | 2000.00 | Hyderabad | Delhi | India |
2 | Mukesh | 40 | 5000.00 | New York | USA | |
3 | Sumit | 45 | 4500.00 | Muscat | Oman | |
4 | Kaushik | 25 | 2500.00 | Kolkata | India |
This table is not in first normal form because we have City column repeated two times and you can see some problems in the current table. This table always reserves space on the disk for two cities, whether the person stays in two cities or not.
To eliminate the repeating columns and bring the table to the first normal form, separate the table into two tables. Put the repeating columns into one of the tables as below −
CUSTOMERS Table
ID | Name | Age | Salary |
---|---|---|---|
1 | Ramesh | 32 | 2000.00 |
2 | Mukesh | 40 | 5000.00 |
3 | Sumit | 45 | 4500.00 |
4 | Kaushik | 25 | 2500.00 |
CUSTOMERS_ADDRESS Table
ID | City | Country |
---|---|---|
1 | Hyderabad | India |
1 | Delhi | India |
2 | New York | USA |
3 | Muscat | Oman |
4 | Kolkata | India |
Now we have normalized tables which are meeting requirements to be in First Normal Form and now we can assign multiple cities for the same customer without wasting space.