Presentation is loading. Please wait.

Presentation is loading. Please wait.

Normalization Amit Bhawnani & Nimesh Shah. What is normalization We need some formal measure of why one grouping of attributes into a relational schema.

Similar presentations


Presentation on theme: "Normalization Amit Bhawnani & Nimesh Shah. What is normalization We need some formal measure of why one grouping of attributes into a relational schema."— Presentation transcript:

1 Normalization Amit Bhawnani & Nimesh Shah

2 What is normalization We need some formal measure of why one grouping of attributes into a relational schema may be better than another Measure of “goodness” or quality of the design An analytical technique used during logical database design Offers a strategy for constructing relations and identifying keys

3 Normal Forms 1 NF 2 NF 3 NF 4 NF 5 NF Normal forms are INCREMENTAL

4 1 NF Eliminate repeating groups; attributes must have only atomic values Emp_idnamesalaryphone 101Abc100009821011111, 9821044444 102LMN120000 103XYZ780000226201111, 0226243333, 9820012345 Problems with the above design ? Employee

5 1 NF Soln 1: Emp_idphonenamesalary 1019821011111Abc10000 1019821044444Abc10000 102LMN120000 1030226201111XYZ78000 1030226243333XYZ78000 1039820012345XYZ78000 Problems with the above design ? Redundancy Insertion anomalies Deletion anomalies Updation anomalies

6 1 NF Soln 2: Emp_idnamesalaryphone1phone2phone3 101Abc1000098210111119821044444 102LMN120000 103XYZ78000022620111102262433339820012345 Problems with the above design ?

7 1 NF Soln 3: Emp_idnamesalary 101Abc10000 102LMN120000 103XYZ78000 Emp_idphone 1019821011111 1019821044444 1030226201111 1030226243333 1039820012345

8 Functional Dependency Require that the value for a certain set of attributes determines uniquely the value for another set of attributes. Functional dependencies define properties of the schema and not of any particular tuple in the relation. The functional dependency   

9 Functional Dependency Employee project details Emp_idProject_noEmp_namesalaryProject_name 1011ABC10000ProjA 1012ABC10000ProjB 1023LMN120000ProjC 1031XYZ78000ProjA 1032XYZ78000ProjB Emp_id -> {emp_name, salary} Project_no -> project_name Emp_id,project_no -> emp_name,salary,project_name Emp_name -> emp_id, project_name, salary, project name ???

10 2 NF Eliminate fields that are facts about only a subset of the key so that all non-key fields are fully functionally dependent on the primary key A relation is said to be in 2NF if and only if it is in 1 NF and every non-key attribute is fully functionally dependent on the primary key.

11 2 NF Employee project details Emp_idProject_noEmp_namesalaryProject_name 1011ABC10000ProjA 1012ABC10000ProjB 1023LMN120000ProjC 1031XYZ78000ProjA 1032XYZ78000ProjB Problems with the above design ? Redundancy Insertion anomalies Deletion anomalies Updation anomalies

12 2 NF Project_noProject_name 1ProjA 2ProjB 3ProjC Emp_idnamesalary 101Abc10000 102LMN120000 103XYZ78000 Emp_idProject_no 1011 2 1023 1032 3 Employee Project Employee_Project

13 3NF A relation should not have a non-key attribute functionally determine determined by another non-key attribute. Every non-key attribute must provide a fact about the key, the whole key, and nothing but the key.

14 3 NF Emp_idEmp_namesalaryDept_idDept_nam e Deptmgr_empid 101Abc10000ADeptA 102LMN120000ADeptA101 103XYZ78000BDeptB Emp_id -> {emp_name, salary, dept_id, dept_name, deptmr_empid} dept_id -> {dept_name, deptmgr_empid}

15 3 NF Dept_idDept_nameDeptmgr_empid ADeptA101 BDeptB103 Emp_idEmp_namesalaryDept_id 101Abc10000A 102LMN120000A 103XYZ78000B Employee Department

16 4 NF Eliminate all but one independent, multi-valued facts. If we have two or more multi valued independent attributes in the same relation schema we get into a problem of having to repeat every value of one of the attributes with every value of the other attribute to keep the relation state consistent and to maintain the independence among the attributes involved.

17 4 NF Emp_nameProject_nameDependent_name SmithXJohn SmithYAnna SmithXAnna SmithYJohn BrownWJim BrownXJim BrownYJim BrownZJim BrownWJoan BrownXJoan BrownYJoan BrownZJoan MVD (Multi valued dependency) Emp_name ->> project_name Emp_name ->> dependent_name

18 4 NF Emp_nameProject_name SmithX Y BrownW X Y Z Emp_nameDependent_name SmithAnna SmithJohn BrownW Jim BrownJoan BrownBob

19 5 NF Eliminate join dependencies A relation is said to be in 5 NF if and only if it is in 4 NF and every “join dependency” in the relation is implied by its key.

20 5 NF AgentManufacturerProduct MetroMarutiCar MetroMarutiVan AlphaM&MTruck AlphaM&MCar AlphaHondaCar AlphaHondaBike If an agent represents a company, and the company manufactures a product, then the agent will deal in that product.

21 5 NF AgentManufacturer MetroMaruti AlphaM&M AlphaHonda ManufacturerProduct MarutiCar MarutiVan M&MTruck M&MCar HondaBike HondaCar

22 Denormalization Process of attempting to optimize the read performance of a database by adding redundant data

23 Classroom exercise 1 Suppose you are given a relation R = (A,B,C,D,E) with the following functional dependencies: {CE -> D,D -> B,C -> A}. – Find all candidate keys. – Identify the best normal form that R satisfies (1NF, 2NF, 3NF)

24 Classroom exercise 1 Answer. – The only key is {C,E} – The relation is in 1NF

25 Classroom exercise 2 You are given the following set of functional dependencies for a relation R(A,B,C,D,E,F), F = {AB -> C,DC -> AE,E -> F}. – What are the keys of this relation? – Is this relation in 3NF? If not, explain why by showing one violation.

26 Classroom exercise 2 Answer – {A,B,D} and {B,C,D} – No, all functional dependencies are actually violating this. No dependency contains a superkey on its left side.


Download ppt "Normalization Amit Bhawnani & Nimesh Shah. What is normalization We need some formal measure of why one grouping of attributes into a relational schema."

Similar presentations


Ads by Google