The Normal Form rules are the basic rules that are created by the Relational Database concept creater Edgar F. Codd. The main purpose of these is to create database tables that do not have redundancy for the data inside. There are basically three NF variations 1NF, 2NF, 3NF (Actually now on it goes up to 6NF by other theoreticians but basic structure is based on 1NF 2NF 3NF) .
1NF points out:
- Table should not have columns that are based on same data
- Create separate tables for each group of related data and identify each row with a unique column (the primary key).
Example:
(Manager, Employee1, Employee2 ) are the columns but there are two Employee column that violate rule one.
(Manager, Employee) is good solution but it violates still second rule.
(Manager, EmployeeID) is intuitive solution since each Employee has only one Manager. Now our table is proper for 1NF.
2NF points out:
- Remove subset of data that causes multiple rows includes same information and create seperate table for them
-Use foreign keys to relate the tables that are newly created and previous one
EXAMPLE:
(EmpID,FirstName, LastName, City, Zipcode, ) is our table but if there are two employee with same city so zipcodem it makes two row with redundant data. So it is more appropriate to use another table that includes cities and correspondence zipcodes. In addition new new structure makes easier to add, remove or update address information. Instead of updating all the rows that have same city and zipcode, we just need to update one row in the new table.
(EmpID, FirstName, LastName, AddID) (AddID, City, ZipCode)
3NF points out:
-Each attribute in the table must be fully determined by a key, separate other columns to other table.
EXAMPLE:
(CustomerID, OrderNum, UnitPrice, Quantity, Total) in this table all the attributes are fully depended to CustomerID but the Total. Total is determined by the UnitPrice*Quantity so it is not fully depended to key. It can be deleted.
(CustomerID, OrderNum, UnitPrice, Quantity) is new table
Hiç yorum yok:
Yorum Gönder