Uploaded by Saem Mashhud Tariq

DATABASE NORMALIZATION

advertisement
NORMALIZATION IN DATABASES
First Normal Form (1NF) is the first step in the normalization process of
relational databases. It is a set of rules that specifies that a relation(table) must
have atomic values, meaning that each attribute(column) should contain only one
value, and that each tuple(row) must be unique.
The key requirements of 1NF are:
Eliminate Repeating Groups: The table should not contain repeating groups of
data in any of its columns. For example, if you have a table of customers and each
customer can have multiple phone numbers, you should not store all the phone
numbers in a single column, instead, you should create a separate table for phone
numbers and link it to the customer table using a foreign key.
Create a Primary Key: Each table should have a primary key, which uniquely
identifies each record in the table. This can be a single column or a combination of
columns.
Ensure Atomicity: Each attribute(column) of a table should contain atomic values,
meaning that it should not contain multiple values or lists of values. For example,
if you have a table of customers and one of the columns is "Address", you should
not store the address as a single string that includes the street, city, state, and zip
code. Instead, you should create separate columns for each component of the
address.
By following these rules, you can ensure that your tables are well-structured and
that you can avoid data anomalies that can occur when data is duplicated or
stored in a non-atomic form.
NORMALIZATION IN DATABASES
Second Normal Form (2NF) is the second step in the normalization process of
relational databases. It builds on the first normal form (1NF) by ensuring that all
non-key attributes of a table are functionally dependent on the whole primary
key.
The key requirements of 2NF are:
The table must be in 1NF: Before applying the rules of 2NF, the table must already
be in 1NF.
Remove Partial Dependencies: Any non-key attributes that are functionally
dependent on only a part of the primary key should be removed from the table
and placed in a new table. This ensures that each table represents a single logical
entity.
Create new tables: The non-key attributes that have been removed in step 2
should be placed in a new table. The new table should have a primary key that
includes the attributes that were removed from the original table.
By following these rules, you can ensure that your tables are in 2NF and that each
table represents a single logical entity. This helps to avoid data duplication and
inconsistencies, and makes it easier to update and maintain your database.
Second Normal Form (2NF) is a normalization rule in database design that helps
ensure data integrity by reducing data redundancy. A table is in second normal
form if it is in first normal form (1NF) and every non-key column in the table is
dependent on the entire primary key.
Here is an example to illustrate the concept of 2NF:
Consider a database table called "Orders" with the following columns:
OrderID (primary key)
ProductID (primary key)
ProductName
Quantity
NORMALIZATION IN DATABASES
This table violates the 2NF because the ProductName column is dependent on the
ProductID column and not on the entire primary key. If multiple orders contain the
same product, the ProductName would be repeated for each row of the table,
which can lead to data redundancy.
To normalize this table into 2NF, we need to create a new table for the
ProductName and its corresponding ProductID. The new tables would be
structured like this:
Orders Table:
OrderID (primary key)
ProductID (primary key)
Quantity
Products Table:
ProductID (primary key)
ProductName
Now, the Orders table is in 2NF, and there is no longer any data redundancy. Each
table represents a single logical entity, and every non-key column is dependent on
the entire primary key.
In summary, 2NF is an important step in database normalization that ensures that
data is organized in a way that reduces redundancy and maintains data integrity.
NORMALIZATION IN DATABASES
Third Normal Form (3NF) is the third step in the normalization process of
relational databases. It builds on the first and second normal forms (1NF and 2NF)
by ensuring that all non-key attributes of a table are functionally dependent only
on the primary key and not on other non-key attributes.
The key requirements of 3NF are:
The table must be in 2NF: Before applying the rules of 3NF, the table must already
be in 2NF.
Remove Transitive Dependencies: Any non-key attributes that are functionally
dependent on other non-key attributes should be removed from the table and
placed in a new table. This ensures that each table represents a single logical
entity.
Create new tables: The non-key attributes that have been removed in step 2
should be placed in a new table. The new table should have a primary key that
includes the attributes that were removed from the original table.
By following these rules, you can ensure that your tables are in 3NF and that each
table represents a single logical entity without any transitive dependencies. This
helps to avoid data duplication and inconsistencies, and makes it easier to update
and maintain your database.
Third Normal Form (3NF) is a normalization rule in database design that helps
ensure data integrity by reducing data redundancy and eliminating transitive
dependencies. A table is in third normal form if it is in second normal form (2NF)
and every non-key column is dependent on the primary key only.
NORMALIZATION IN DATABASES
Here is an example to illustrate the concept of 3NF:
Consider a database table called "Customers" with the following columns:
CustomerID (primary key)
CustomerName
CustomerCity
CustomerState
CustomerZip
This table violates the 3NF because the columns CustomerCity, CustomerState,
and CustomerZip are dependent on each other and not on the primary key. If
multiple customers reside in the same city, the city and its corresponding state
and zip code would be repeated for each row of the table, which can lead to data
redundancy.
To normalize this table into 3NF, we need to create a new table for the city, state,
and zip code. The new tables would be structured like this:
Customers Table:
CustomerID (primary key)
CustomerName
CityID (foreign key)
Cities Table:
CityID (primary key)
CityName
States Table:
StateID (primary key)
NORMALIZATION IN DATABASES
StateName
ZipCodes Table:
ZipID (primary key)
ZipCode
Now, the Customers table is in 3NF, and there is no longer any data redundancy or
transitive dependencies. Each table represents a single logical entity, and every
non-key column is dependent on the primary key only.
In summary, 3NF is an important step in database normalization that ensures that
data is organized in a way that reduces redundancy, eliminates transitive
dependencies, and maintains data integrity.
Download