350 likes | 520 Views
ITS232 Introduction To Database Management Systems. Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA ( UiTM ), Kedah | sitinurbaya@kedah.uitm.edu.my | http://www.sitinur151.wordpress.com | | A2-3039 | ext:2561 | 012-7760562 |. CHAPTER 5
E N D
ITS232Introduction To Database Management Systems SitiNurbaya Ismail Faculty of Computer Science & Mathematics, UniversitiTeknologi MARA (UiTM), Kedah | sitinurbaya@kedah.uitm.edu.my | http://www.sitinur151.wordpress.com | | A2-3039 | ext:2561 | 012-7760562 | CHAPTER 5 Normalization Of Database Tables (Part I: Concept & Process)
Chapter 5: Normalization Of Database Tables 5.0 Normalization Of Database Tables 5.1 Database Tables And Normalization 5.2 The Need For Normalization 5.3 The Normalization Process 5.4 Normalization And Database Design 5.5 Denormalization
Chapter 5: Normalization Of Database Tables5.1 Database Tables And Normalization • Table is the basic building block of database design • ER Modeling, yields good table structures, but it is still possible to create poor table structures even in a good database design • How do you recognize a poor tables structure, and how do you produce good table? • Normalization • A process of evaluating and correcting table structures to minimize data redundancies, thereby reducing the possibility of data anomalies • Works through a series of stages called normal forms
Chapter 5: Normalization Of Database Tables5.1 Database Tables And Normalization In Chapter 4, ER Modeling, we have adopted a top-down approach to database design that begins by identifying the entities and relationship Normalization is a bottom-up approach to database design that begins by examining the relationships between attributes
Chapter 5: Normalization Of Database Tables5.1 Database Tables And Normalization Top-down Bottom-up { Normalization } { ER Modeling }
Chapter 5: Normalization Of Database Tables5.1 Database Tables And Normalization position employeeNO BRANCH branchNO* EMPLOYEE BRANCH name branchNO salary has EMPLOYEE city 1 M BRANCH(branchNO,city) EMPLOYEE(employeeNO,name,position,salary,branchNO*)
Chapter 5: Normalization Of Database Tables5.2 The Need For Normalization • Normalization is typically used with ER Modeling • There are two common situations in which database designers use normalization: • Designing a new database • When designing a new database structure based on the business requirements of the end users, the database designer will construct a data model using technique such as Crow’s Foot notation ERDs • After the initial design is complete, the designer can used normalization to analyze the relationships that exist among the attributes within each entity, to determine if the structure can be improved through normalization
Chapter 5: Normalization Of Database Tables5.2 The Need For Normalization • Normalization is typically used with ER Modeling • There are two common situations in which database designers use normalization: • Modifying existing data structures • Sometimes database designer are asked to modify existing data structures that can be in form of flat files, spreadsheet, or older database structures • Normalization process can be used to analyze the relationship among the attributes or fields in the data structures, to improve the existing data structure in order to create an appropriate database design
Chapter 5: Normalization Of Database Tables5.2 The Need For Normalization • There for in both situations describe, the need for normalization are: • to analyze the relationship among the attributes or fields in the data structures • to improve the existing data structure in order to create an appropriate database design • Normalization • A process of evaluating and correcting table structures to minimize data redundancies, thereby reducing the possibility of data anomalies
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process • When we design a database, the main objective is to create an accurate representation of data, relationship between the data, and constrains on the data that is relevant. • To achieve this objective, we have to identify suitable set of relations (table) by creating good table structure. • Normalization • A process of evaluating and correcting table structures to minimize data redundancies, thereby reducing the possibility of data anomalies • Works through a series of stages called normal forms
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process • The most commonly used normal forms: • First Normal Form (1NF) • Second Normal Form (2NF) • Third Normal Form (3NF) • 2NF is better than 1NF; 3NF is better than 2NF • Highest normalization is not always desirable; joint vs redundancy • For most business database design purposes, 3NF is as high as we need to go in normalization process
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process • Every normal form is based on functional dependenciesbetween attributes in a relationship • Each relationship can be normalized into a specific form to avoid anomalies • Anomalies? • anomaly = abnormality • ideally a field value change, should be made only in a single place • Data redundancy, however, fosters an abnormal condition by forcing field value changes in many different locations • Insertion anomalies • Deletion anomalies • Modification anomalies
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Data Redundancies Denormalization Normalization Formal technique for analyzing relations based on their Primary Key (or candidate keys) and functional dependencies The techniqueexecuted as a series of steps (stage). Each step corresponds to a specific normal form, that have specific characteristic As normalization proceeds, the relations become progressively more restricted (stronger) in format and also less vulnerable to anomalies
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Denormalization Figure 1: Diagrammatic illustration of the relationship between the normal forms Normalization Relationship between normalization form
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Data Sources Users Users’ requirements specification Forms/reports that are used or generated by the enterprise Sources describing the enterprise such as data dictionary and corporate data model Transfer attributes into table format Unnormalized Form (UNF) Remove repeating group First Normal Form (1NF) Remove partial dependencies Second Normal Form (2NF) Remove transitive dependencies Third Normal Form (3NF)
1)Repeat Group 2)PK is not defined UNF 1)Remove Repeat Group 2)Defined PK composite PK consist of attributes 1NF Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Normalization Process Relation/table Format • Have repeating group-PK not defined (1 Table) (1 or 2 Tables) • No repeating group-PK defined-Test partial dependency Test for partial dependency If (exist) (2 or 3 Tables) (more then 1 table) (ab …. TD) 1 (a ……. TD) 2 (b ….… TD) 3 2NF • No repeating group-PK defined-No partial dependency-Test transitive dependency Test for transitive dependency If (exist) (a, b x, y) (a c, d) (b z) (c d) • No repeating group-PK defined-No partial dependency-No transitive dependency 3NF (3 or 4 Tables)
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Functional Dependencies An important concept associated with normalization is functional dependency which describes the relationship between attributes In this section, you will learn about functional dependency and then focus on the particular characteristics of functional dependency that are useful for normalization
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Functional dependencies: Describe the relationship between attributes in a relation. For example, if A and B are attributes of relation R, Bis functionally dependent on A (denoted A B), if each value of A is associated with exactly one value of B. (A and B may each consist of one or more attributes.) Characteristic Of Functional Dependencies For the discussion on functional dependency, assume that a relational schema has attributes (A,B,C,…,Z) and that the database is describe by a single universal relation called R=(A,B,C,…,Z). This assumption means that every attribute in the database has a unique name
B is functionally B A dependent on A Chapter 5: Normalization Of Database Tables5.3 The Normalization Process R(A,B) A B Characteristic Of Functional Dependencies Consider a relation with attributes A and B, where attribute Bis functionally dependent on attribute A To describe the relationship between attributes A and B is to say that A functionally determines B
B is functionally B A dependent on A Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Determinant: Refers to the attribute, or a group of attributes, on the left handed side of the arrow of a functional dependency Characteristic Of Functional Dependencies When a functional dependency exist, the attribute or group of attributes on the left-handed side of the arrow is called determinant
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process EMPLOYEE BRANCH BRANCH(branchNO,city) EMPLOYEE(employeeNO,name,position,salary,branchNO*) Characteristic Of Functional Dependencies
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Unnormalized Form (UNF)/(0NF) • Unnormalized Form (UNF)/(0NF) A table that contains one or more repeating groups To create an unnormalized table • Transform the data from the information source (e.g. form) into table format with columns and rows
employeeNO functionally position employeeNO determines position Chapter 5: Normalization Of Database Tables5.3 The Normalization Process S21 Manager Characteristic Of Functional Dependencies Consider the attributesemployeeNOand positionof the EMPLOYEErelation For a specific employeeNO(S21), we can determine the positionof that member of employee as Manager employeeNOfunctionally determinesposition
position does not functionally employeeNO position determine emlpoyeeNO Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Manager S21 S5 Characteristic Of Functional Dependencies However the next figure illustrate that the opposite is not true, as positiondoes not functionally determinesemployeeNO A member of employee holds one position; however, they maybe several members of employee with the same position
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Characteristic Of Functional Dependencies • Functional dependency can be describe by two types: • Full functional dependency (Partial dependency) • Will be used to transform 1NF 2NF • Transitive dependency • Will be used to transform 2NF 3NF
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process R(A,B,C) A B,C Characteristic Of Functional Dependencies • Functional dependency can be describe by two types: 1. Full functional dependency (Partial dependency) Full functional dependency indicates that if A and B are attributes of a relation, B is fully functionally dependent on A, if B is functionally dependent on A, but not on any proper subset of A A depending based on only a part of composite primary key
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process R(A,B,C) A B B C Characteristic Of Functional Dependencies • Functional dependency can be describe by two types: 2. Transitive dependency A, B and C are attributes of a relation such that if A B and B C, then C is transitively dependent on A through B (Provided that A is not functionally dependent on B or C) A dependency of one non prime attribute on another non prime attribute
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process First Normal Form (1NF) First Normal Form (1NF) A relation in which the intersection of each row and column contains one and only one value A relation is in 1NF if every attribute for every tuple have a value and domain for each attribute can not be simplified anymore
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Second Normal Form (2NF) • Second Normal Form (2NF) A relation that is in 1NF and every non-PK attribute is fully functionally depends on the PK Based on the concept of partial dependency (dependencies' based on only a part of composite PK) 2NF applies to relations with composite keys, that is, relations with PK composed of two or more attributes A relation with a single-attribute PK is automatically in at least 2NF
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process Third Normal Form (3NF) • Third Normal Form (3NF) A relation that is in 1NF and 2NF and which no non-PK attribute is transitively dependent on the PK Based on the concept of transitive dependency, where; A, B and C are attributes of a relation such that if A B and B C then C is transitively dependent on A through B (Provided that A is not functionally dependent on B or C) 3NF applies to relations with transitive dependency A relation that have no transitive dependency are already in 3NF
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process UNF To 1NF • Nominate an attribute or group of attributes to act as the key for the unnormalized table • Identify the repeating group(s) in the unnormalized table which repeats for the key attribute(s), remove the repeating group by • entering appropriate data into the empty columns of rows containing the repeating data • Fill the blanks by duplicating the non repeating data, where required • This approach is commonly referred to as ”flattening table” • This approach will produce redundancy in a relationship, but it can be eliminated in higher normalization process
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process 1NF To 2NF • Identify the primary key for the 1NF relation • Identify the functional dependencies in the relation. • Draw functional dependencies diagram • Write functional dependencies in relational schema • If partial dependencies exist on the primary key remove them by placing them in a new relation along with a copy of their determinant
Chapter 5: Normalization Of Database Tables5.3 The Normalization Process R (A, B, C) with transitive dependencies: A B B C Simplified R to: R1 (A, B*) R2 (B, C) 2NF To 3NF • Identify the primary key in the 2NF relation • Identify functional dependencies in the relation • If transitive dependency exist on the PK, remove them by placing them in a new relation along with a copy of their determinant • Guidelines:
Chapter 5: Normalization Of Database Tables5.4 Normalization & Database Design • Normalization should be part of the design process. • Make sure the proposed entities meet the required normal form before the table structures are created • Be aware of good design principles and procedures as well as normalization procedures • ERD: is created by interactive process, begin by identifying relevant entities, their attributes, and their relationship. ERD provides the big picture/macro view, of an organization’s data requirements & operations. • Normalization: focuses on the characteristics of specific entities: that is represents macro view of the entities within the ERD • Therefore the two techniques are used in an iterative and incremental process
Chapter 5: Normalization Of Database Tables5.5 Denormalization Data Redundancies Denormalization Normalization