Lending-Schema (Branch-Name, Branch-City, Assets, Customer-Name, Loan-Number, Amount)
Lending-Schema (Branch-Name, Branch-City, Assets, Customer-Name, Loan-Number, Amount)
Problems:
. 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.
2. 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) |x| ∏R2 (r)
5. Review: domain.
Domain is atomic if its elements are considered to be indivisible units
. Examples of non-atomic domains: set of names, composite
attributes
. In relational schema all domains are usually assumed to be atomic
6. First Normal Form
. A relational schema R is in first normal form if the domains of all
attributes of R are atomic
We assume all relations are in first normal form
If a relational schema is in first normal form, can we say that it is a “good”
scheme. No. Let’s go on.
7. Functional Dependencies
. We’ll build our theory on functional dependencies.
. Functional Dependency is a constraint that requires that the value for a
certain set of attributes determines uniquely the value for another set of
attributes.
A functional dependency is a generalization of the notion of a key.
8. Review: keys.
. K is a superkey for relation schema R if and only if K → R
. K is a candidate key for R if and only if
. K → R, and
. for no α ⊂ K, α → R
. Functional dependencies allow us to express constraints that cannot be
expressed using superkeys. Consider the schema:
Loan-info-schema = (customer-name, loan-number, branch-name, amount).
We expect this set of functional dependencies to hold (be satisfied):
loan-number → amount
loan-number → branch-name
but would not expect the following to hold:
loan-number → customer-name
9. Use of Functional Dependencies
. We use functional dependencies to:
. test relations to see if they are legal under a given set of functional
dependencies.
If a relation r is legal under a set F of functional
dependencies, we say that r satisfies F.
. specify constraints on the set of legal relations
We say that F holds on R if all legal relations on R satisfy the
set of functional dependencies F.
13. Look back at our goal: lossless-join decomposition (#4 and #2).
. 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) |x| ∏R2 (r)
14. How do we know that decomposition is a lossless join?
. A decomposition of R into R1 and R2 is lossless join if and only if
. at least one of the following dependencies is in F+:
. R1 ∩ R2 → R1
R1 ∩ R2 → R2
Example: Lossless join.
Decompose the relation schema Lending-schema into:
Branch-schema = (branch-name, branch-city,assets)
Loan-info-schema = (customer-name, loan-number, branch-name, amount)