This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
miniworld
Requirements & collection analysis
Conceptual Design
Data Model Mapping
Database Requirements
Conceptual Schema ( ER diagram )DBMS independent
DBMS specificConceptual Schema ( Relations )
refinement
• primary key constraint• foreign key constraint
Schema Refinement and Normal Forms
•Conceptual database design gives us a set of relation schemas and integrity constraints
•Given a design, how do we know it is good or not?
•A design can be evaluated from various perspectives, our focus is on data redundancy
Conceptual design
Schemas ICs
The Evils of Redundancy• Redundancy is at the root of several
problems associated with relational schemas:– redundant storage– Insertion/update/deletion anomalies
• Solution: Decomposition If we break Hourly_Emps into Hourly_Emps2 and Wages,
then we don’t have updates, insertion, deletion anomalies.
Hourly_Emps2 WagesS N L R H 123-22-3666 Attishoo 48 8 40 231-31-5368 Smiley 22 8 30 131-24-3650 Smethurst 35 5 30 434-26-3751 Guldu 35 5 32 612-67-4134 Madayan 35 8 40
R W8 105 7
•Should a relation be decomposed?• If a relation is not in certain form, some problems (e.g., redundancy) will arise, are these problems tolerable?
•Aforementioned anomalies•Potential performance loss: Queries over the original relation may required to join the decomposed relations
•How to decompose a relation? Two properties must be preserved:
• lossless-join: the data in the original relation can be recovered from the smaller relations
•dependency-preservation: all constraints on the original relation must still hold by enforcing some constraints on each of the small relations
Decomposition Concerns
Functional Dependencies (FDs)In a relation schema R, a set of attributes X
functionally determines a set of attributes Y if and only if whenever two tuples of R agree on X value, they must necessarily agree on the Y value.
XY
][][][][),(
2121
2,1
YtYtXtXtRrtt
XY: Y is functionally dependent on X, or
X uniquely determines Y orX functionally determines Y, or X determines Y
where r(R) is an instance of R,RYRX and
X Y ZX1 Y2 Z1X1 Y2 Z2X2 Y2 Z3
Does this data set violate X->Y?Does this data set violate Z->Y?
X Y ZX1 Y1 Z1X1 Y1 Z2X1 Y2 Z1
Does this data set violate X->Y?Does this data set violate XY->Z?Does this data set violate Z->X?
• An FD is a statement about all allowable relations.
– Must be identified based on semantics of application.– Given some allowable instance r1 of R, we can check
if it violates some FD f, but we cannot tell if f holds over R!
• A primary key constraint is a special case of an FD
– The attributes in the key play the role of X, and the set of all attributes in the relation plays the role of Y
Example 1Hourly_Emps (ssn, name, lot, rating, hrly_wages,
hrs_worked)
• Notation: We will denote this relation schema by listing the attributes: SNLRWH– This is really the set of attributes {S,N,L,R,W,H}.– Sometimes, we will refer to all attributes of a relation by
using the relation name. (e.g., Hourly_Emps for SNLRWH)
• Some FDs on Hourly_Emps:– ssn is the key: SSNLRWH (or {S}{S,N,L,R,W,H})– rating determines hrly_wages : RW
F infers the following additional functional dependencies:
F {SSN}->{DNAME,DMGRSSN}
F {SSN}->{SSN}
F {DNUMBER}->{DNAME}
A set of dependencies may imply some additional dependencies.
Dependency Reasoning
Some important questions
1. Given a set of attributes X, what attributes can be determined by X
2. Given an FD set, what other dependencies are implied
3. Given an FD set F, what is the minimum set of dependencies that is equivalent to F
•Armstrong’s Axioms where X, Y, Z are sets of attributes:– Reflexivity: If X Y, then XY. – Augmentation: If XY, then XZ YZ for any Z.– Transitivity: If X Y and YZ, then XZ.
Armstrong’s Axioms
PROOFS• Reflexive rule: If X Y, then XY.
Let {t1,t2} r(R) such that t1[X]=t2[X]Since Y X, t1[X]=t2[X] t1[Y]=t2[Y]
XY.
PROOFS (Cont’d)• Transitive rule: If XY and YZ, then XZ.