Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Normalizing Database Designs

Similar presentations


Presentation on theme: "Chapter 9 Normalizing Database Designs"— Presentation transcript:

1 Chapter 9 Normalizing Database Designs
Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 9 Normalizing Database Designs

2 NORMALIZATION What is normalization?
Normalization is a procedure that is used to eliminate data redundancy while ensuring data integrity. Data integrity : ensures the quality of the data in the database (satisfies data constraint rules. i.e. Primary Key, Foreign Key, etc.) Data redundancy: if data can be found in two places in a single database (direct redundancy) or calculated using data from different parts of the database (indirect redundancy) then redundancy exists. The goal is to remove redundancy and other data modification (insertion, update and deletion) problems

3 What is Data redundancy?
When a group of attributes has multiple values then we say there is a repeating group of attributes in the relation Example: Movie Title Year Length FilmType StudioName StarName Harry Potter 2003 180 Color WarnerBros JK Rowling Mark Hamill Harrison Ford Flight Plan 2005 110 Fox Judie Foster Sean Penn 190 Mike Mayers REPEATING GROUP

4 Problems of redundancy
If redundancy exists then this can cause problems during normal database operations: Updates - when some data needs altering, we find it's in several places. Insertion - When we want to insert something, we can't because some other data is also required which we don't have. Deletion - When something is deleted, other data is lost as well.

5 Integrity Constraints
An integrity constraint is a rule that restricts the values that may be present in the database. Entity Integrity: The rows (or tuples) in a relation represent entities, and each one must be uniquely identified. Hence we have the primary key that must have a unique not-null value for each row. Referential Integrity: This constraint involves the foreign keys. Foreign keys tie the relations together, so it is vitally important that the links are correct. Every foreign key must either be null or its value must be the actual value of a key in another relation.

6 Entity Integrity: Selecting Primary Keys
Primary key is the most important characteristic of an entity Single attribute or some combination of attributes Primary key’s function is to guarantee entity integrity Primary keys and foreign keys work together to implement relationships Properly selecting primary key has direct bearing on efficiency and effectiveness

7 Natural Keys and Primary Keys
Natural key is a real-world identifier used to uniquely identify real-world objects Familiar to end users and forms part of their day-to-day business vocabulary Generally, data modeler uses natural identifier as primary key of entity being modeled May instead use composite primary key or surrogate key

8 Primary Key Guidelines
Attribute that uniquely identifies entity instances in an entity set Could also be combination of attributes Main function is to uniquely identify an entity instance or row within a table Guarantee entity integrity, not to “describe” the entity Primary keys and foreign keys implement relationships among entities Behind the scenes, hidden from user

9

10 When to Use Composite Primary Keys
Composite primary keys useful in two cases: As identifiers of composite entities In which each primary key combination is allowed once in M:N relationship As identifiers of weak entities In which weak entity has a strong identifying relationship with the parent entity Automatically provides benefit of ensuring that there cannot be duplicate values

11

12 When to Use Composite Primary Keys (cont’d.)
When used as identifiers of weak entities normally used to represent: Real-world object that is existent-dependent on another real-world object Real-world object that is represented in data model as two separate entities in strong identifying relationship Dependent entity exists only when it is related to parent entity

13 When To Use Surrogate Primary Keys
Especially helpful when there is: No natural key Selected candidate key has embedded semantic contents Selected candidate key is too long or cumbersome

14 When To Use Surrogate Primary Keys (cont’d.)
If you use surrogate key: Ensure that candidate key of entity in question performs properly Use “unique index” and “not null” constraints

15

16 KEY Key: We can say that one or more attributes of a Relation can be a
Key for that Relation. Those attributes functionally determine all other attributes of the relation. (There can’t be more than one let say two distinct tuple that is key for a Relation) No proper subset of the Relation functionally determines all other attributes of Relation. A key must be minimal. Super Key: Is an attribute or set of attributes whose closure contains all attributes of the table. (A table may contain many S.K.) Candidate Key: Is a minimal S.K. (Contains no attributes that are not needed to form a S.K.) (A table may have many C.K.) Primary Key: The C.K. chosen for implementation. Each table has only 1 P.K.

17 Example StaffBranch staffNo sName position salary branchNo bAddress SL21 John White Manager 30000 B005 22 Deer Rd, London SG37 Ann Beech Assistant 12000 B003 163 Main St, Glasgow SG14 David Ford Supervisor 18000 SA9 Mary Howe 9000 B007 16 Argyll St, Aberdeen SG5 Susan Brand 24000 SL41 Julie Lee Functional Dependency? Describes the relationship between the attributes in a relation Reasonable Functional Dependencies (FDs): staffNo  sName, position, salary branchNo  bAddress So, what is the Key for StaffBranch Relation?

18 Closure Closure is denoted by: { }+
Closure of an attribute or set of attributes is the set that contains all attributes that can be determined directly or indirectly by the given attribute or set of attributes. Procedure for Computing Closure of {A1,A2,…..An} START ans={A1,A2,…..An} REPEAT until ans does not change for each FD if the Left Hand Side(LHS) is in ans ADD the Right Hand Side(RHS) to ans STOP Closure is denoted by: { }+

19 Computing Closure Consider the following Relation and FDs:
StaffBranch(staffNo,sName,position,salary,branchNo,bAddress) FDs: staffNo  sName, position, salary branchNo  bAddress Compute the Closures of given attributes: {staffNo}+= {staffNo,sName,position,salary} {branchNo}+= {branchNo,bAddress} {staffNo,branchNo}+={StaffNo,sName,position,salary, branchNo, bAddress}

20 Boyce Codd Normal Form (BCNF)
A table is in BCNF if the determinant of all Functional Dependencies are Super Key. Procedure for BCNF: Step1: Check if the Functional Dependencies violate BCNF. Compute closure of all determinants. Find the Functional Dependencies (F.D.s) that violate BCNF. Step2: Choose any violating F.D. and form a new table from its closure. List all F.D.s that valid on the new table. Find the Primary Key. Step3: Eliminate all the non key attributes of the table formed in Step2 from the table that you normalize. Form a new table from the remainders. List all F.D.s that are valid on the new table.

21 EXAMPLES will be solved in the lecture session.

22 Database Tables and Normalization
Process for evaluating and correcting table structures to minimize data redundancies Reduces data anomalies Series of stages called normal forms: First normal form (1NF) Second normal form (2NF) Third normal form (3NF)

23 Database Tables and Normalization (cont’d.)
Normalization (continued) 2NF is better than 1NF; 3NF is better than 2NF For most business database design purposes, 3NF is as high as needed in normalization Highest level of normalization is not always most desirable Denormalization produces a lower normal form Increased performance but greater data redundancy

24 The Need for Normalization
Example: company that manages building projects Charges its clients by billing hours spent on each contract Hourly billing rate is dependent on employee’s position Periodically, report is generated that contains information such as displayed in Table 6.1

25

26 The Need for Normalization (cont’d.)
Structure of data set in Figure 9.1 does not handle data very well Table structure appears to work; report is generated with ease Report may yield different results depending on what data anomaly has occurred Relational database environment is suited to help designer avoid data integrity problems

27 The Normalization Process
Each table represents a single subject No data item will be unnecessarily stored in more than one table All nonprime attributes in a table are dependent on the primary key Each table is void of insertion, update, and deletion anomalies

28

29 The Normalization Process (cont’d.)
Objective of normalization is to ensure that all tables are in at least 3NF Higher forms are not likely to be encountered in business environment Normalization works one relation at a time Progressively breaks table into new set of relations based on identified dependencies

30

31 The Normalization Process (cont’d.)
Partial dependency Exists when there is a functional dependence in which the determinant is only part of the primary key Transitive dependency Exists when there are functional dependencies such that X → Y, Y → Z, and X is the primary key

32 Conversion to First Normal Form
Repeating group Group of multiple entries of same type can exist for any single key attribute occurrence Relational table must not contain repeating groups Normalizing table structure will reduce data redundancies Normalization is three-step procedure

33 Conversion to First Normal Form (cont’d.)
Step 1: Eliminate the Repeating Groups Eliminate nulls: each repeating group attribute contains an appropriate data value Step 2: Identify the Primary Key Must uniquely identify attribute value New key must be composed Step 3: Identify All Dependencies Dependencies are depicted with a diagram

34

35 Conversion to First Normal Form (cont’d.)
Dependency diagram: Depicts all dependencies found within given table structure Helpful in getting bird’s-eye view of all relationships among table’s attributes Makes it less likely that you will overlook an important dependency

36

37 Conversion to First Normal Form (cont’d.)
First normal form describes tabular format: All key attributes are defined No repeating groups in the table All attributes are dependent on primary key All relational tables satisfy 1NF requirements Some tables contain partial dependencies Dependencies are based on part of the primary key Should be used with caution

38 Conversion to Second Normal Form
Step 1: Make New Tables to Eliminate Partial Dependencies Write each key component on separate line, then write original (composite) key on last line Each component will become key in new table Step 2: Reassign Corresponding Dependent Attributes Determine attributes that are dependent on other attributes At this point, most anomalies have been eliminated

39

40 Conversion to Second Normal Form (cont’d.)
Table is in second normal form (2NF) when: It is in 1NF and It includes no partial dependencies: No attribute is dependent on only portion of primary key

41 Conversion to Third Normal Form
Step 1: Make New Tables to Eliminate Transitive Dependencies For every transitive dependency, write its determinant as PK for new table Determinant: any attribute whose value determines other values within a row

42 Conversion to Third Normal Form (cont’d.)
Step 2: Reassign Corresponding Dependent Attributes Identify attributes dependent on each determinant identified in Step 1 Identify dependency Name table to reflect its contents and function

43

44 Conversion to Third Normal Form (cont’d.)
A table is in third normal form (3NF) when both of the following are true: It is in 2NF It contains no transitive dependencies

45 Improving the Design Table structures should be cleaned up to eliminate initial partial and transitive dependencies Normalization cannot, by itself, be relied on to make good designs Valuable because it helps eliminate data redundancies

46 Improving the Design (cont’d.)
Issues to address, in order, to produce a good normalized set of tables: Evaluate PK Assignments Evaluate Naming Conventions Refine Attribute Atomicity Identify New Attributes

47 Improving the Design (cont’d.)
Identify New Relationships Refine Primary Keys as Required for Data Granularity Maintain Historical Accuracy Evaluate Using Derived Attributes

48

49

50 Surrogate Key Considerations
When primary key is considered to be unsuitable, designers use surrogate keys Data entries in Table 6.4 are inappropriate because they duplicate existing records No violation of entity or referential integrity

51 Higher-Level Normal Forms
Tables in 3NF perform suitably in business transactional databases Higher-order normal forms are useful on occasion Two special cases of 3NF: Boyce-Codd normal form (BCNF) Fourth normal form (4NF)

52 The Boyce-Codd Normal Form
Every determinant in table is a candidate key Has same characteristics as primary key, but for some reason, not chosen to be primary key When table contains only one candidate key, the 3NF and the BCNF are equivalent BCNF can be violated only when table contains more than one candidate key

53 The Boyce-Codd Normal Form (cont’d.)
Most designers consider the BCNF as a special case of 3NF Table is in 3NF when it is in 2NF and there are no transitive dependencies Table can be in 3NF and fail to meet BCNF No partial dependencies, nor does it contain transitive dependencies A nonkey attribute is the determinant of a key attribute

54

55

56

57 Fourth Normal Form (4NF)
Table is in fourth normal form (4NF) when both of the following are true: It is in 3NF No multiple sets of multivalued dependencies 4NF is largely academic if tables conform to following two rules: All attributes dependent on primary key, independent of each other No row contains two or more multivalued facts about an entity

58

59

60 Normalization and Database Design
Normalization should be part of the design process Make sure that proposed entities meet required normal form before table structures are created Many real-world databases have been improperly designed or burdened with anomalies You may be asked to redesign and modify existing databases

61 Normalization and Database Design (cont’d.)
ER diagram Identify relevant entities, their attributes, and their relationships Identify additional entities and attributes Normalization procedures Focus on characteristics of specific entities Micro view of entities within ER diagram Difficult to separate normalization process from ER modeling process

62

63

64

65

66

67 Denormalization Creation of normalized relations is important database design goal Processing requirements should also be a goal If tables are decomposed to conform to normalization requirements: Number of database tables expands

68 Denormalization (cont’d.)
Joining the larger number of tables reduces system speed Conflicts are often resolved through compromises that may include denormalization Defects of unnormalized tables: Data updates are less efficient because tables are larger Indexing is more cumbersome No simple strategies for creating virtual tables known as views

69 Data-Modeling Checklist
Data modeling translates specific real-world environment into data model Represents real-world data, users, processes, interactions Data-modeling checklist helps ensure that data-modeling tasks are successfully performed Based on concepts and tools learned in Part II

70


Download ppt "Chapter 9 Normalizing Database Designs"

Similar presentations


Ads by Google