Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Normalization.

Similar presentations


Presentation on theme: "Database Normalization."— Presentation transcript:

1 Database Normalization

2 Database Normalization What are the problems here?

3 Database Normalization Entity Attributes and their types
Redundant Data Anomaly and its types Normalization and its forms

4 Any thing about which data is stored.
Normalization Entity Any thing about which data is stored. Examples: Person, Company, Event

5 An entity is represented by a set of attributes.
Normalization Entity Property of an entity An entity is represented by a set of attributes. field

6 Example Attributes Entity STUDENT Student Id Name Address
Phone No STUDENT Entity

7 Attribute Types Simple(component) attributes Composite attributes Single-valued attributes Multi-valued attributes Derived attributes Key attributes Non-Key attributes

8 Which one is Composite Attribute?
Name First Name Middle Name Last Name Which one is Composite Attribute?

9 Domain The set (range) of allowed values for an attribute
Roll No. Grade 1 A 2 B 3 F 4 C Domain for Grade attribute { A, B, C, D, F }

10 Redundant Data Employee Table EMPID NAME DEPT SALARY COURSE GRADE 100
Asad Marketing 42000 IT A 140 Waheed Accounting 39000 Management B 110 Majid Info Systems 41500 DBMS

11 An anomaly is an inconsistent or contradictory state of the database.

12 Anomalies Types of Anomalies Insertion Anomaly Deletion Anomaly
Update Anomaly

13 Insertion Anomaly Occurrence of an error or inconsistency due to the insertion of new data in a table

14 Example Insertion Anomaly
Employee Table EMPID NAME DEPT SALARY COURSE GRADE 100 Asad Marketing 42000 IT A 140 Waheed Accounting 39000 110 Majid Info Systems 41500 DBMS 4000 Management B

15 Deletion Anomaly A valid fact is lost when a record is deleted.
Occurrence of an error or inconsistency due to the deletion of data in a table A valid fact is lost when a record is deleted.

16 Example Deletion Anomaly
Employee Table EMPID NAME DEPT SALARY COURSE GRADE 100 Asad Marketing 42000 SPSS A Management B 140 Waheed Accounting 39000 110 Majid Info Systems 41500 Intro. to IT

17 Update Anomaly One occurrence of a fact is changed,
Occurrence of an error or inconsistency due to the modification of data in a table One occurrence of a fact is changed, but not all occurrences.

18 Example Update Anomaly
Employee Table EMPID NAME DEPT SALARY COURSE GRADE 100 Asad Marketing 42000 SPSS A 140 Waheed Accounting 39000 110 Majid Info Systems 41500 Intro. to IT B 45000 Management

19 Normalization Basic Idea 1. Divide a table into two or more tables and
2. Define relationships between the tables. Objectives Minimize data duplication Efficient data retrieval Less space Less errors

20 Normalization Two basic conditions No redundant data No anomalies.

21 1st three levels often used
Normal Forms 7 Levels / Stages of normalization 1st three levels often used

22 7 Normal Forms Unnormalized data Normalized data 1NF 2NF 3NF BCNF 4NF
5NF (PJNF) DKNF Normalized data

23 Steps in normalization
Remove Table with repeating groups Repeating Groups 1st Normal Form Partial Dependencies 2nd Normal Form Transitive Dependencies 3rd Normal Form Determinant / Candidate Keys Boyce-Codd Normal Form Multivalued Dependencies 4th Normal Form Removing Remaining anomalies 5th Normal Form (Project Join NF) Removing Remaining anomalies Domain Key Normal Form

24 Result Card Card No.: 1 Issue date: 3/4/8
Example Card No.: 1 Issue date: 3/4/8 Student ID: Student Name: ABC Student Address: 45-C, Lahore. Course ID Course Name Total Marks Obtained Marks 101 W 100 70 102 X 50 103 Y 80 104 Z 60 1st Grand Total: 260 Representation

25 Before Normalization Redundant Data 2nd Representation Crd_No Is_Date
S_ID SName Addr C_ID C_Name TMrks OMrks GTtl 1 3/4/8 111 ABC 45-C 101 W 100 70 260 102 X 50 103 Y 80 104 Z 60 2 95 MNO 40-D 230 Redundant Data 2nd Representation

26 There are no repeating attribute-groups.
Normal Form 1st There are no repeating attribute-groups.

27 Before Normalization Best Approach 3rd Representation 1 3/4/8 111 ABC
CrdNo IsDate SId SName Adr CId CName TMrks OMrks GTtl 1 3/4/8 111 ABC 45C 101 W 100 70 102 X 50 103 Y 80 260 2 95 MNO 40D 104 Z 60 230 Best Approach 3rd Representation

28 Before Normalization 4th Representation Crd_No Is_Date S_ID SName Addr
C_ID C_Name TMrks OMrks GTtl 1 3/4/8 111 ABC 45-C 101 W 100 70 260 102 X 50 103 Y 80 104 Z 60 2 95 MNO 40-D 230 Crd_No Is_Date S_ID SName Addr C_ID C_Name TMrks OMrks GTtl 1 3/4/8 111 ABC 45-C 101 W 100 70 260 2 95 MNO 40-D 103 Y 230 102 X 100 50 103 Y 100 80 104 Z 100 60 104 Z 100 60 4th Representation

29 Normal Form 1st Process Identify the primary key of denormalized table. Repeating attribute-groups of the table are separated out in form of a new table. Primary key of old table is added into new table as foreign key. Identify the primary key of new table.

30 Repeating Attributes Card No.: 1 Issue date: 3/4/8
Student ID: Student Name: ABC Student Address: 45-C, Lahore. Course ID Course Name Total Marks Obtained Marks 101 W 100 70 102 X 50 103 Y 80 104 Z 60 Grand Total: 260 Repeating attribute-groups

31 Repeating Attributes Grand Total: 260 5th Card No.: 1
Issue date: 3/4/8 Student ID: Student Name: ABC Student Address: 45-C, Lahore. Course ID Course Name Total Marks Obtained Marks 101 W 100 70 Course ID Course Name Total Marks Obtained Marks 102 X 100 50 Course ID Course Name Total Marks Obtained Marks 103 Y 100 80 Course ID Course Name Total Marks Obtained Marks 104 Z 100 60 5th Grand Total: 260 Representation

32 } Normal Form 1st Card No PK Issue Date Student ID Student Name
Student Address Grand Total Card No FK Course ID Course Name Total Marks Obtained Marks } CP Table-2 Table-1

33 } Normal Form 1st Card No PK Issue Date Student ID Student Name
Student Address Grand Total Card No FK Course ID Course Name Total Marks Obtained Marks } CP Table-2 Table-1

34 There is no partial dependency.
Normal Form 2nd There is no partial dependency. part  partial Partial dependency: An attribute depends upon the part of the key, but not on the whole key.

35 Normal Form 2nd Relation is in 1NF.
Conditions Relation is in 1NF. All non-key attributes should depend upon Key attribute. Implementable if Compound Key Exist.

36 Normal Form 2nd Process All non-key attributes that depend upon part of key are separated out in a new table along with part of key on which these attributes depend. Identify the primary key of new table and add it back to the old table as foreign key.

37 } Normal Form 2nd Card No FK Course ID CP Course Name Total Marks
Obtained Marks } CP

38 }CP } Normal Form 2nd Card No FK Course ID Course Name Total Marks
Obtained Marks } CP }CP Card No FK Course ID FK Obtained Marks Course ID PK Course Name Total Marks

39 There is no transitive dependency.
Normal Form 3rd There is no transitive dependency. Transitive dependency: A non-key attribute depends upon another non-key attribute.

40 Normal Form 3rd Relation is in 2NF.
Conditions Relation is in 2NF. All non-key attributes depend on key attribute.

41 Normal Form 3rd Process All non-key attributes depending on any non-key attribute are separated out in form of new table. Identify the primary key of new table and add it back to the old table as foreign key.

42 Normal Form 3rd Card No PK Issue Date Student ID FK Card No PK
Grand Total Card No PK Issue Date Student ID Student Name Student Address Grand Total Student ID PK Student Name Student Address Any thing wrong here?

43 }CP Normalization Over all Result Card No FK Course ID FK
Obtained Marks }CP Card No PK Issue Date Student ID FK Grand Total Student ID PK Student Name Student Address Course ID PK Course Name Total Marks

44 Invoice Practice Exercise Invoice no.: 1 Invoice date: 3/4/8
Customer ID: Customer Name: ABC Customer Address: 45-C, Lahore Phone : P_ID P_Name QTY Price Total 101 W 3 20 60 102 X 2 10 103 Y 30 104 Z 1 Invoice Total: 200


Download ppt "Database Normalization."

Similar presentations


Ads by Google