SlideShare a Scribd company logo
1 of 31
©Silberschatz, Korth and Sudarshan
7.1
Database System Concepts
Relational Database Design
©Silberschatz, Korth and Sudarshan
7.2
Database System Concepts
Relational Database Design
 First Normal Form
 Pitfalls in Relational Database Design
 Functional Dependencies
 Decomposition
 Boyce-Codd Normal Form
 Third Normal Form
 Multivalued Dependencies and Fourth Normal Form
 Overall Database Design Process
©Silberschatz, Korth and Sudarshan
7.3
Database System Concepts
First Normal Form
 Domain is atomic if its elements are considered to be indivisible units
 Examples of non-atomic domains:
 address, composite attributes with component attribute street and city
 dependent_name of an employee in a Banking enterprise is a multivalued
attribute
 A relational schema R is in first normal form (1NF) if the domains of all
attributes of R are atomic
 Non-atomic values complicate storage and encourage redundant
(repeated) storage of data
 E.g. Set of accounts stored with each customer, and set of owners stored
with each account
©Silberschatz, Korth and Sudarshan
7.4
Database System Concepts
First Normal Form (Contd.)
 Atomicity is actually a property of how the elements of the
domain are used.
 E.g. Strings would normally be considered indivisible
 Suppose that students are given roll numbers which are strings of
the form CS0012 or EE1127
 If the first two characters are extracted to find the department, the
domain of roll numbers is not atomic.
 Doing so is a bad idea: leads to encoding of information in
application program rather than in the database.
©Silberschatz, Korth and Sudarshan
7.5
Database System Concepts
Pitfalls in Relational Database Design
 Relational database design requires that we find a
“good” collection of relation schemas. A bad design
may lead to
 Repetition of Information.
 Inability to represent certain information.
 Design Goals:
 Avoid redundant data
 Ensure that relationships among attributes are
represented
 Facilitate the checking of updates for violation of
database integrity constraints.
©Silberschatz, Korth and Sudarshan
7.6
Database System Concepts
Example
 Consider the relation schema:
Lending-schema = (branch-name, branch-city, assets,
customer-name, loan-number, amount)
 Redundancy:
 Data for branch-name, branch-city, assets are repeated for each loan that a
branch makes
 Wastes space
 Complicates updating, introducing possibility of inconsistency of assets value
 Null values
 Cannot store information about a branch if no loans exist
 Can use null values, but they are difficult to handle.
©Silberschatz, Korth and Sudarshan
7.7
Database System Concepts
Decomposition
 Decompose the relation schema Lending-schema into:
Branch-schema = (branch-name, branch-city,assets)
Loan-info-schema = (customer-name, loan-number,
branch-name, amount)
 All attributes of an original schema (R) must appear in
the decomposition (R1, R2):
R = R1  R2
 Lossless-join decomposition.
For all possible relations r on schema R
r = R1 (r) R2 (r)
©Silberschatz, Korth and Sudarshan
7.8
Database System Concepts
Example of Non Lossless-Join Decomposition
 Decomposition of R = (A, B)
R1 = (A) R2 = (B)
A B



1
2
1
A


B
1
2
r
A(r) B(r)
A (r) B (r)
A B




1
2
1
2
©Silberschatz, Korth and Sudarshan
7.9
Database System Concepts
Lossless join decomposition
©Silberschatz, Korth and Sudarshan
7.10
Database System Concepts
Lossless join decomposition
©Silberschatz, Korth and Sudarshan
7.11
Database System Concepts
Lossless join decomposition
©Silberschatz, Korth and Sudarshan
7.12
Database System Concepts
Lossless join decomposition
©Silberschatz, Korth and Sudarshan
7.13
Database System Concepts
Lossless join decomposition
©Silberschatz, Korth and Sudarshan
7.14
Database System Concepts
Goal — Devise a Theory for the Following
 Decide whether a particular relation R is in “good” form.
 In the case that a relation R is not in “good” form, decompose it
into a set of relations {R1, R2, ..., Rn} such that
 each relation is in good form
 the decomposition is a lossless-join decomposition
 Our theory is based on:
 functional dependencies
 multivalued dependencies
©Silberschatz, Korth and Sudarshan
7.15
Database System Concepts
Functional Dependencies
 A functional dependency is a constraint that specifies the
relationship between two sets of attributes where one set can
accurately determine the value of other sets.
 It is denoted as X → Y, where X is a set of attributes that is
capable of determining the value of Y.
 A functional dependency is a generalization of the notion of a
key.
©Silberschatz, Korth and Sudarshan
7.16
Database System Concepts
Functional Dependencies
©Silberschatz, Korth and Sudarshan
7.17
Database System Concepts
Functional Dependencies (Cont.)
 Let R be a relation schema
  R and   R
 The functional dependency
  
holds on R if and only if for any legal relations r(R), whenever any
two tuples t1 and t2 of r agree on the attributes , they also agree
on the attributes . That is,
t1[] = t2 []  t1[ ] = t2 [ ]
 Example: Consider r(A,B) with the following instance of r.
 On this instance, A  B does NOT hold, but B  A does hold.
1 4
1 5
3 7
©Silberschatz, Korth and Sudarshan
7.20
Database System Concepts
Functional Dependencies (Cont.)
 A functional dependency is trivial if it is satisfied by all instances
of a relation
 E.g.
 customer-name, loan-number  customer-name
 customer-name  customer-name
 In general,    is trivial if   
©Silberschatz, Korth and Sudarshan
7.21
Database System Concepts
Closure of a Set of Functional
Dependencies
 Given a set F set of functional dependencies, there are certain
other functional dependencies that are logically implied by F.
 E.g. If A  B and B  C, then we can infer that A  C
 The set of all functional dependencies logically implied by F is the
closure of F.
 We denote the closure of F by F+.
 We can find all of F+ by applying Armstrong’s Axioms:
 if   , then    (reflexivity)
 if   , then      (augmentation)
 if   , and   , then    (transitivity)
 These rules are
 sound (generate only functional dependencies that actually hold) and
 complete (generate all functional dependencies that hold).
©Silberschatz, Korth and Sudarshan
7.22
Database System Concepts
Functional Dependencies (Cont.)
©Silberschatz, Korth and Sudarshan
7.23
Database System Concepts
Closure of Functional Dependencies
(Cont.)
 We can further simplify manual computation of F+ by using
the following additional rules.
 If    holds and    holds, then     holds (union)
 If     holds, then    holds and    holds
(decomposition)
 If    holds and     holds, then     holds
(pseudotransitivity)
The above rules can be inferred from Armstrong’s axioms.
©Silberschatz, Korth and Sudarshan
7.24
Database System Concepts
Example
 R = (A, B, C, G, H, I)
F = { A  B
A  C
CG  H
CG  I
B  H}
 some members of F+
 A  H
 by transitivity from A  B and B  H
 AG  I
 by augmenting A  C with G, to get AG  CG
and then transitivity with CG  I
 CG  HI
 from CG  H and CG  I : “union rule” can be inferred from
– definition of functional dependencies, or
– Augmentation of CG  I to infer CG  CGI, augmentation of
CG  H to infer CGI  HI, and then transitivity
©Silberschatz, Korth and Sudarshan
7.26
Database System Concepts
Closure of Attribute Sets
 The closure of a set of attributes X is the set of those attributes
that can be functionally determined from X. The closure of X
is denoted as X+. When given a closure problem, you'll have a
set of functional dependencies over which to compute the
closure and the set X for which to find the closure.
 Finding the closure of a set of attributes is needed for problems
related to normalization. For example, you need to know how
to compute the closure of a set of attributes to check if a set of
attributes is a candidate key or a superkey. You also need this
algorithm to decompose non-normal tables into normal forms.
©Silberschatz, Korth and Sudarshan
7.27
Database System Concepts
Closure of Attribute Sets
 Algorithm to compute +, the closure of  under F
result := ;
while (changes to result) do
for each    in F do
begin
if   result then result := result  
end
©Silberschatz, Korth and Sudarshan
7.28
Database System Concepts
Example of Attribute Set Closure
 R = (A, B, C, G, H, I)
 F = {A  B
A  C
CG  H
CG  I
B  H}
 (AG)+
1. result = AG
2. result = ABCG (A  C and A  B)
3. result = ABCGH (CG  H and CG  AGBC)
4. result = ABCGHI (CG  I and CG  AGBCH)
©Silberschatz, Korth and Sudarshan
7.29
Database System Concepts
Example of Attribute Set Closure
©Silberschatz, Korth and Sudarshan
7.30
Database System Concepts
Example of Attribute Set Closure
©Silberschatz, Korth and Sudarshan
7.31
Database System Concepts
Example of Attribute Set Closure
©Silberschatz, Korth and Sudarshan
7.32
Database System Concepts
Example of Attribute Set Closure
©Silberschatz, Korth and Sudarshan
7.33
Database System Concepts
Example of Attribute Set Closure
©Silberschatz, Korth and Sudarshan
7.34
Database System Concepts
Uses of Attribute Closure
There are several uses of the attribute closure algorithm:
 Testing for superkey:
 To test if  is a superkey, we compute +, and check if + contains
all attributes of R.
 Testing functional dependencies
 To check if a functional dependency    holds (or, in other words,
is in F+), just check if   +.
 That is, we compute + by using attribute closure, and then check if
it contains .
 Is a simple and cheap test, and very useful
 Computing closure of F
 For each   R, we find the closure +, and for each S  +, we
output a functional dependency   S.

More Related Content

Similar to Lecture_W9_Normalization.ppt

Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx
Database System Concepts, 6th Ed.©Silberschatz, Korth and .docxDatabase System Concepts, 6th Ed.©Silberschatz, Korth and .docx
Database System Concepts, 6th Ed.©Silberschatz, Korth and .docxrandyburney60861
 
Relational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptRelational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptShahidSultan24
 
03 Relational Databases.ppt
03 Relational Databases.ppt03 Relational Databases.ppt
03 Relational Databases.pptAmitpatil226799
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational ModelHazemWaheeb1
 
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbjhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbWrushabhShirsat3
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptxRUpaliLohar
 
DATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.pptDATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.pptYashShirude1
 
U2_ER_modeling.pptx
U2_ER_modeling.pptxU2_ER_modeling.pptx
U2_ER_modeling.pptxssusera7b660
 
Database Design E-R Model.pdf
Database Design E-R Model.pdfDatabase Design E-R Model.pdf
Database Design E-R Model.pdfAbithaSam
 
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational modelAzizul Mamun
 
relational algebra and calculus queries .ppt
relational algebra and calculus queries .pptrelational algebra and calculus queries .ppt
relational algebra and calculus queries .pptShahidSultan24
 
Relational database concept
Relational database conceptRelational database concept
Relational database conceptfikirabc
 
Query optimization
Query optimizationQuery optimization
Query optimizationNeha Behl
 

Similar to Lecture_W9_Normalization.ppt (20)

ch7-clean.ppt
ch7-clean.pptch7-clean.ppt
ch7-clean.ppt
 
Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx
Database System Concepts, 6th Ed.©Silberschatz, Korth and .docxDatabase System Concepts, 6th Ed.©Silberschatz, Korth and .docx
Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx
 
App c
App cApp c
App c
 
Relational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptRelational Algebra and relational queries .ppt
Relational Algebra and relational queries .ppt
 
03 Relational Databases.ppt
03 Relational Databases.ppt03 Relational Databases.ppt
03 Relational Databases.ppt
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational Model
 
Er model
Er modelEr model
Er model
 
ER Models.ppt
ER Models.pptER Models.ppt
ER Models.ppt
 
Relational Model
Relational ModelRelational Model
Relational Model
 
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbjhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptx
 
DATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.pptDATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
 
U2_ER_modeling.pptx
U2_ER_modeling.pptxU2_ER_modeling.pptx
U2_ER_modeling.pptx
 
Database Design E-R Model.pdf
Database Design E-R Model.pdfDatabase Design E-R Model.pdf
Database Design E-R Model.pdf
 
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational model
 
relational algebra and calculus queries .ppt
relational algebra and calculus queries .pptrelational algebra and calculus queries .ppt
relational algebra and calculus queries .ppt
 
ch6.pptx
ch6.pptxch6.pptx
ch6.pptx
 
Relational database concept
Relational database conceptRelational database concept
Relational database concept
 
Query optimization
Query optimizationQuery optimization
Query optimization
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

Lecture_W9_Normalization.ppt

  • 1. ©Silberschatz, Korth and Sudarshan 7.1 Database System Concepts Relational Database Design
  • 2. ©Silberschatz, Korth and Sudarshan 7.2 Database System Concepts Relational Database Design  First Normal Form  Pitfalls in Relational Database Design  Functional Dependencies  Decomposition  Boyce-Codd Normal Form  Third Normal Form  Multivalued Dependencies and Fourth Normal Form  Overall Database Design Process
  • 3. ©Silberschatz, Korth and Sudarshan 7.3 Database System Concepts First Normal Form  Domain is atomic if its elements are considered to be indivisible units  Examples of non-atomic domains:  address, composite attributes with component attribute street and city  dependent_name of an employee in a Banking enterprise is a multivalued attribute  A relational schema R is in first normal form (1NF) if the domains of all attributes of R are atomic  Non-atomic values complicate storage and encourage redundant (repeated) storage of data  E.g. Set of accounts stored with each customer, and set of owners stored with each account
  • 4. ©Silberschatz, Korth and Sudarshan 7.4 Database System Concepts First Normal Form (Contd.)  Atomicity is actually a property of how the elements of the domain are used.  E.g. Strings would normally be considered indivisible  Suppose that students are given roll numbers which are strings of the form CS0012 or EE1127  If the first two characters are extracted to find the department, the domain of roll numbers is not atomic.  Doing so is a bad idea: leads to encoding of information in application program rather than in the database.
  • 5. ©Silberschatz, Korth and Sudarshan 7.5 Database System Concepts Pitfalls in Relational Database Design  Relational database design requires that we find a “good” collection of relation schemas. A bad design may lead to  Repetition of Information.  Inability to represent certain information.  Design Goals:  Avoid redundant data  Ensure that relationships among attributes are represented  Facilitate the checking of updates for violation of database integrity constraints.
  • 6. ©Silberschatz, Korth and Sudarshan 7.6 Database System Concepts Example  Consider the relation schema: Lending-schema = (branch-name, branch-city, assets, customer-name, loan-number, amount)  Redundancy:  Data for branch-name, branch-city, assets are repeated for each loan that a branch makes  Wastes space  Complicates updating, introducing possibility of inconsistency of assets value  Null values  Cannot store information about a branch if no loans exist  Can use null values, but they are difficult to handle.
  • 7. ©Silberschatz, Korth and Sudarshan 7.7 Database System Concepts Decomposition  Decompose the relation schema Lending-schema into: Branch-schema = (branch-name, branch-city,assets) Loan-info-schema = (customer-name, loan-number, branch-name, amount)  All attributes of an original schema (R) must appear in the decomposition (R1, R2): R = R1  R2  Lossless-join decomposition. For all possible relations r on schema R r = R1 (r) R2 (r)
  • 8. ©Silberschatz, Korth and Sudarshan 7.8 Database System Concepts Example of Non Lossless-Join Decomposition  Decomposition of R = (A, B) R1 = (A) R2 = (B) A B    1 2 1 A   B 1 2 r A(r) B(r) A (r) B (r) A B     1 2 1 2
  • 9. ©Silberschatz, Korth and Sudarshan 7.9 Database System Concepts Lossless join decomposition
  • 10. ©Silberschatz, Korth and Sudarshan 7.10 Database System Concepts Lossless join decomposition
  • 11. ©Silberschatz, Korth and Sudarshan 7.11 Database System Concepts Lossless join decomposition
  • 12. ©Silberschatz, Korth and Sudarshan 7.12 Database System Concepts Lossless join decomposition
  • 13. ©Silberschatz, Korth and Sudarshan 7.13 Database System Concepts Lossless join decomposition
  • 14. ©Silberschatz, Korth and Sudarshan 7.14 Database System Concepts Goal — Devise a Theory for the Following  Decide whether a particular relation R is in “good” form.  In the case that a relation R is not in “good” form, decompose it into a set of relations {R1, R2, ..., Rn} such that  each relation is in good form  the decomposition is a lossless-join decomposition  Our theory is based on:  functional dependencies  multivalued dependencies
  • 15. ©Silberschatz, Korth and Sudarshan 7.15 Database System Concepts Functional Dependencies  A functional dependency is a constraint that specifies the relationship between two sets of attributes where one set can accurately determine the value of other sets.  It is denoted as X → Y, where X is a set of attributes that is capable of determining the value of Y.  A functional dependency is a generalization of the notion of a key.
  • 16. ©Silberschatz, Korth and Sudarshan 7.16 Database System Concepts Functional Dependencies
  • 17. ©Silberschatz, Korth and Sudarshan 7.17 Database System Concepts Functional Dependencies (Cont.)  Let R be a relation schema   R and   R  The functional dependency    holds on R if and only if for any legal relations r(R), whenever any two tuples t1 and t2 of r agree on the attributes , they also agree on the attributes . That is, t1[] = t2 []  t1[ ] = t2 [ ]  Example: Consider r(A,B) with the following instance of r.  On this instance, A  B does NOT hold, but B  A does hold. 1 4 1 5 3 7
  • 18. ©Silberschatz, Korth and Sudarshan 7.20 Database System Concepts Functional Dependencies (Cont.)  A functional dependency is trivial if it is satisfied by all instances of a relation  E.g.  customer-name, loan-number  customer-name  customer-name  customer-name  In general,    is trivial if   
  • 19. ©Silberschatz, Korth and Sudarshan 7.21 Database System Concepts Closure of a Set of Functional Dependencies  Given a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F.  E.g. If A  B and B  C, then we can infer that A  C  The set of all functional dependencies logically implied by F is the closure of F.  We denote the closure of F by F+.  We can find all of F+ by applying Armstrong’s Axioms:  if   , then    (reflexivity)  if   , then      (augmentation)  if   , and   , then    (transitivity)  These rules are  sound (generate only functional dependencies that actually hold) and  complete (generate all functional dependencies that hold).
  • 20. ©Silberschatz, Korth and Sudarshan 7.22 Database System Concepts Functional Dependencies (Cont.)
  • 21. ©Silberschatz, Korth and Sudarshan 7.23 Database System Concepts Closure of Functional Dependencies (Cont.)  We can further simplify manual computation of F+ by using the following additional rules.  If    holds and    holds, then     holds (union)  If     holds, then    holds and    holds (decomposition)  If    holds and     holds, then     holds (pseudotransitivity) The above rules can be inferred from Armstrong’s axioms.
  • 22. ©Silberschatz, Korth and Sudarshan 7.24 Database System Concepts Example  R = (A, B, C, G, H, I) F = { A  B A  C CG  H CG  I B  H}  some members of F+  A  H  by transitivity from A  B and B  H  AG  I  by augmenting A  C with G, to get AG  CG and then transitivity with CG  I  CG  HI  from CG  H and CG  I : “union rule” can be inferred from – definition of functional dependencies, or – Augmentation of CG  I to infer CG  CGI, augmentation of CG  H to infer CGI  HI, and then transitivity
  • 23. ©Silberschatz, Korth and Sudarshan 7.26 Database System Concepts Closure of Attribute Sets  The closure of a set of attributes X is the set of those attributes that can be functionally determined from X. The closure of X is denoted as X+. When given a closure problem, you'll have a set of functional dependencies over which to compute the closure and the set X for which to find the closure.  Finding the closure of a set of attributes is needed for problems related to normalization. For example, you need to know how to compute the closure of a set of attributes to check if a set of attributes is a candidate key or a superkey. You also need this algorithm to decompose non-normal tables into normal forms.
  • 24. ©Silberschatz, Korth and Sudarshan 7.27 Database System Concepts Closure of Attribute Sets  Algorithm to compute +, the closure of  under F result := ; while (changes to result) do for each    in F do begin if   result then result := result   end
  • 25. ©Silberschatz, Korth and Sudarshan 7.28 Database System Concepts Example of Attribute Set Closure  R = (A, B, C, G, H, I)  F = {A  B A  C CG  H CG  I B  H}  (AG)+ 1. result = AG 2. result = ABCG (A  C and A  B) 3. result = ABCGH (CG  H and CG  AGBC) 4. result = ABCGHI (CG  I and CG  AGBCH)
  • 26. ©Silberschatz, Korth and Sudarshan 7.29 Database System Concepts Example of Attribute Set Closure
  • 27. ©Silberschatz, Korth and Sudarshan 7.30 Database System Concepts Example of Attribute Set Closure
  • 28. ©Silberschatz, Korth and Sudarshan 7.31 Database System Concepts Example of Attribute Set Closure
  • 29. ©Silberschatz, Korth and Sudarshan 7.32 Database System Concepts Example of Attribute Set Closure
  • 30. ©Silberschatz, Korth and Sudarshan 7.33 Database System Concepts Example of Attribute Set Closure
  • 31. ©Silberschatz, Korth and Sudarshan 7.34 Database System Concepts Uses of Attribute Closure There are several uses of the attribute closure algorithm:  Testing for superkey:  To test if  is a superkey, we compute +, and check if + contains all attributes of R.  Testing functional dependencies  To check if a functional dependency    holds (or, in other words, is in F+), just check if   +.  That is, we compute + by using attribute closure, and then check if it contains .  Is a simple and cheap test, and very useful  Computing closure of F  For each   R, we find the closure +, and for each S  +, we output a functional dependency   S.