Upload
user-of-using
View
242
Download
0
Embed Size (px)
Citation preview
8/9/2019 Chapter 5 DBMS
1/50
8/9/2019 Chapter 5 DBMS
2/50
Database Systems, 8th Edition 2
Objectives
• In this chapter, you will learn:
– What normalization is and what role it plays inthe database design process
– About the normal orms !"#, $"#, %"#, &'"#,and ("#
– )ow normal orms can be transormed romlower normal orms to higher normal orms
– *hat normalization and + modeling are usedconcurrently to produce a good database design
– *hat some situations re-uire denormalization togenerate inormation eiciently
8/9/2019 Chapter 5 DBMS
3/50
Database Systems, 8th Edition 3
.atabase *ables and "ormalization
• Normalization
– /rocess or evaluating and correcting table
structures to minimize data redundancies
• educes data anomalies
– Wor0s through a series o stages called normal
orms:
• #irst normal orm 1!"#2
• 3econd normal orm 1$"#2
• *hird normal orm 1%"#2
8/9/2019 Chapter 5 DBMS
4/50
Database Systems, 8th Edition 4
.atabase *ables and "ormalization
1continued2
• "ormalization 1continued2
– $"# is better than !"#4 %"# is better than $"#
– #or most business database design purposes,
%"# is as high as needed in normalization
– )ighest level o normalization is not always most
desirable
• Denormalization produces a lower normal orm – /rice paid or increased perormance is greater
data redundancy
8/9/2019 Chapter 5 DBMS
5/50
Database Systems, 8th Edition 5
*he "eed or "ormalization
• +5ample: company that manages building
projects
– 'harges its clients by billing hours spent on
each contract
– )ourly billing rate is dependent on employee6s
position
– /eriodically, report is generated that contains
inormation such as displayed in *able 78!
8/9/2019 Chapter 5 DBMS
6/50
Database Systems, 8th Edition 6
8/9/2019 Chapter 5 DBMS
7/50
8/9/2019 Chapter 5 DBMS
8/50
Database Systems, 8th Edition 8
*he "eed or "ormalization
1continued2
• 3tructure o data set in #igure 78! does not
handle data very well
• *able structure appears to wor04 report
generated with ease
• eport may yield dierent results depending on
what data anomaly has occurred
• elational database environment suited to helpdesigner avoid data integrity problems
8/9/2019 Chapter 5 DBMS
9/50
Database Systems, 8th Edition 9
*he "ormalization /rocess
• +ach table represents a single subject
• "o data item will be unnecessarily stored in
more than one table
• All attributes in a table are dependent on the
primary 0ey
• +ach table void o insertion, update, deletion
anomalies
8/9/2019 Chapter 5 DBMS
10/50
Database Systems, 8th Edition 10
8/9/2019 Chapter 5 DBMS
11/50
Database Systems, 8th Edition 11
*he "ormalization /rocess
1continued2
• Objective o normalization is to ensure all tables
in at least %"#
• )igher orms not li0ely to be encountered in
business environment
• "ormalization wor0s one relation at a time
• /rogressively brea0s table into new set o
relations based on identiied dependencies
8/9/2019 Chapter 5 DBMS
12/50
Database Systems, 8th Edition 12
8/9/2019 Chapter 5 DBMS
13/50
Database Systems, 8th Edition 13
'onversion to #irst "ormal #orm
• epeating group
– 9roup o multiple entries o same type e5ist or
any single 0ey attribute occurrence
• elational table must not contain repeatinggroups
• "ormalizing table structure will reduce data
redundancies• "ormalization is threestep procedure
8/9/2019 Chapter 5 DBMS
14/50
Database Systems, 8th Edition 14
'onversion to #irst "ormal #orm
1continued2
• 3tep !: +liminate the epeating 9roups
– +liminate nulls: each repeating group attribute
contains an appropriate data value
• 3tep $: Identiy the /rimary ;ey
–
8/9/2019 Chapter 5 DBMS
15/50
Database Systems, 8th Edition 15
8/9/2019 Chapter 5 DBMS
16/50
Database Systems, 8th Edition 16
'onversion to #irst "ormal #orm
1continued2
• .ependency diagram:
– .epicts all dependencies ound within given
table structure
– )elpul in getting bird6seye view o allrelationships among table6s attributes
–
8/9/2019 Chapter 5 DBMS
17/50
8/9/2019 Chapter 5 DBMS
18/50
Database Systems, 8th Edition 18
'onversion to #irst "ormal #orm
1continued2
• #irst normal orm describes tabular ormat inwhich:
– All 0ey attributes are deined
– *here are no repeating groups in the table
– All attributes are dependent on primary 0ey
• All relational tables satisy !"# re-uirements
• 3ome tables contain partial dependencies – .ependencies based on part o the primary 0ey
– 3hould be used with caution
8/9/2019 Chapter 5 DBMS
19/50
Database Systems, 8th Edition 19
'onversion to 3econd "ormal #orm
• 3tep !: Write +ach ;ey 'omponenton a 3eparate =ine
– Write each 0ey component on separate line, then
write original 1composite2 0ey on last line – +ach component will become 0ey in new table
• 3tep $: Assign 'orresponding .ependent Attributes
– .etermine those attributes that are dependenton other attributes
– At this point, most anomalies have beeneliminated
8/9/2019 Chapter 5 DBMS
20/50
Database Systems, 8th Edition 20
8/9/2019 Chapter 5 DBMS
21/50
Database Systems, 8th Edition 21
'onversion to 3econd "ormal #orm
1continued2
• *able is in second normal orm 1$"#2 when:
– It is in !"# and
– It includes no partial dependencies:
• "o attribute is dependent on only portion o
primary 0ey
8/9/2019 Chapter 5 DBMS
22/50
Database Systems, 8th Edition 22
'onversion to *hird "ormal #orm
• 3tep !: Identiy +ach "ew .eterminant
– #or every transitive dependency, write its
determinant as /; or new table
– .eterminant: any attribute whose valuedetermines other values within a row
• 3tep $: Identiy the .ependent Attributes
– Identiy attributes dependent on eachdeterminant identiied in 3tep !
• Identiy dependency
– "ame table to relect its contents and unction
8/9/2019 Chapter 5 DBMS
23/50
Database Systems, 8th Edition 23
'onversion to *hird "ormal #orm
1continued2
• 3tep %: emove the .ependent Attributes rom
*ransitive .ependencies
– +liminate all dependent attributes in transitive
relationship1s2 rom each o the tables – .raw new dependency diagram to show all
tables deined in 3teps !–%
– 'hec0 new tables as well as tables modiied in
3tep %
• +ach table has determinant
• "o table contains inappropriate dependencies
8/9/2019 Chapter 5 DBMS
24/50
Database Systems, 8th Edition 24
8/9/2019 Chapter 5 DBMS
25/50
Database Systems, 8th Edition 25
'onversion to *hird "ormal #orm
1continued2
• A table is in third normal orm 1%"#2 when both
o the ollowing are true:
– It is in $"#
– It contains no transitive dependencies
8/9/2019 Chapter 5 DBMS
26/50
Database Systems, 8th Edition 26
Improving the .esign
• *able structures cleaned up to eliminate initial
partial and transitive dependencies
• "ormalization cannot, by itsel, be relied on to
ma0e good designs
• It is valuable because its use helps eliminate
data redundancies
8/9/2019 Chapter 5 DBMS
27/50
Database Systems, 8th Edition 27
Improving the .esign 1continued2
• Issues to address in order to produce a goodnormalized set o tables: – +valuate /; Assignments
– +valuate "aming 'onventions – eine Attribute Atomicity – Identiy "ew Attributes – Identiy "ew elationships
– eine /rimary ;eys as e-uired or .ata9ranularity – sing .erived Attributes
8/9/2019 Chapter 5 DBMS
28/50
Database Systems, 8th Edition 28
8/9/2019 Chapter 5 DBMS
29/50
Database Systems, 8th Edition 29
3urrogate ;ey 'onsiderations
• When primary 0ey is considered to be
unsuitable, designers use surrogate 0eys
• .ata entries in *able 78% are inappropriate
because they duplicate e5isting records – "o violation o entity or reerential integrity
8/9/2019 Chapter 5 DBMS
30/50
Database Systems, 8th Edition 30
)igher=evel "ormal #orms
• *ables in %"# perorm suitably in business
transactional databases
• )igher order normal orms useul on occasion
• *wo special cases o %"#:
– &oyce'odd normal orm 1&'"#2
– #ourth normal orm 1("#2
8/9/2019 Chapter 5 DBMS
31/50
Database Systems, 8th Edition 31
*he &oyce'odd "ormal #orm
1&'"#2
• +very determinant in table is a candidate 0ey
– )as same characteristics as primary 0ey, but or
some reason, not chosen to be primary 0ey
• When table contains only one candidate 0ey,the %"# and the &'"# are e-uivalent
• &'"# can be violated only when table contains
more than one candidate 0ey
8/9/2019 Chapter 5 DBMS
32/50
Database Systems, 8th Edition 32
*he &oyce'odd "ormal #orm
1&'"#2 1continued2
•
8/9/2019 Chapter 5 DBMS
33/50
Database Systems, 8th
Edition 33
8/9/2019 Chapter 5 DBMS
34/50
Database Systems, 8th
Edition 34
8/9/2019 Chapter 5 DBMS
35/50
Database Systems, 8th
Edition 35
8/9/2019 Chapter 5 DBMS
36/50
8/9/2019 Chapter 5 DBMS
37/50
Database Systems, 8th
Edition 37
8/9/2019 Chapter 5 DBMS
38/50
Database Systems, 8th
Edition 38
8/9/2019 Chapter 5 DBMS
39/50
Database Systems, 8th
Edition 39
"ormalization and .atabase .esign
• "ormalization should be part o the design
process
•
8/9/2019 Chapter 5 DBMS
40/50
Database Systems, 8th
Edition 40
"ormalization and .atabase .esign
1continued2
• + diagram
– Identiy relevant entities, their attributes, and
their relationships
– Identiy additional entities and attributes
• "ormalization procedures
– #ocus on characteristics o speciic entities
–
8/9/2019 Chapter 5 DBMS
41/50
Database Systems, 8th
Edition 41
8/9/2019 Chapter 5 DBMS
42/50
Database Systems, 8th
Edition 42
8/9/2019 Chapter 5 DBMS
43/50
Database Systems, 8th
Edition 43
8/9/2019 Chapter 5 DBMS
44/50
Database Systems, 8th
Edition44
8/9/2019 Chapter 5 DBMS
45/50
Database Systems, 8th
Edition45
8/9/2019 Chapter 5 DBMS
46/50
Database Systems, 8th
Edition46
.enormalization
• 'reation o normalized relations is important
database design goal
• /rocessing re-uirements should also be a goal
• I tables decomposed to conorm tonormalization re-uirements:
– "umber o database tables e5pands
8/9/2019 Chapter 5 DBMS
47/50
Database Systems, 8th
Edition47
.enormalization 1continued2
• @oining the larger number o tables reducessystem speed
• 'onlicts oten resolved through compromises
that may include denormalization• .eects o unnormalized tables:
– .ata updates are less eicient because tablesare larger
– Inde5ing is more cumbersome – "o simple strategies or creating virtual tables
0nown as views
8/9/2019 Chapter 5 DBMS
48/50
Database Systems, 8th
Edition48
3ummary
• "ormalization is used to minimize data
redundancies
• #irst three normal orms 1!"#, $"#, and %"#2
are most commonly encountered• *able is in !"# when:
– All 0ey attributes are deined
– All remaining attributes are dependent onprimary 0ey
8/9/2019 Chapter 5 DBMS
49/50
Database Systems, 8th
Edition49
3ummary 1continued2
• *able is in $"# when it is in !"# and contains no
partial dependencies
• *able is in %"# when it is in $"# and contains no
transitive dependencies• *able that is not in %"# may be split into new tables
until all o the tables meet %"# re-uirements
• "ormalization is important partbut only parto
the design process
8/9/2019 Chapter 5 DBMS
50/50
th 50
3ummary 1continued2
• *able in %"# may contain multivalueddependencies
– "umerous null values or redundant data
• 'onvert %"# table to ("# by: – 3plitting table to remove multivalued
dependencies
• *ables are sometimes denormalized to yield
less IBO, which increases processing speed