23
REVIEW

Review

Embed Size (px)

DESCRIPTION

Review. Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000. Algebra. Relational Algebra Operations. Basic operations Selection ( ) Selects a subset of rows from relation. Projection ( ) Deletes unwanted columns from relation. - PowerPoint PPT Presentation

Citation preview

Page 1: Review

REVIEW

Page 2: Review

22

Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000

Page 3: Review

ALGEBRA

Page 4: Review

44

RELATIONAL ALGEBRA OPERATIONS Basic operations

Selection ( ) Selects a subset of rows from

relation. Projection ( )

Deletes unwanted columns from relation.

Cartesian product ( ) Combine two relations.

Set-difference ( ) Tuples in relation 1, but not in

relation 2. Union ( )

Tuples in relation 1 or in relation 2.

Page 5: Review

55

Suppliers (S)

sid

sname

address

Parts (P)

pid

pname

color

Catalog (C)

sid

pid

cost

Page 6: Review

66

Suppliers (S)

sid

sname

address

Parts (P)

pid

pname

color

Catalog (C)

sid

pid

cost

Page 7: Review

77

Suppliers (S)

sid

sname

address

Parts (P)

pid

pname

color

Catalog (C)

sid

pid

cost

Page 8: Review

88

Suppliers (S)

sid

sname

address

Parts (P)

pid

pname

color

Catalog (C)

sid

pid

cost

Page 9: Review

99

Suppliers (S)

sid

sname

address

Parts (P)

pid

pname

color

Catalog (C)

sid

pid

cost

Page 10: Review

1010

Suppliers (S)

sid

sname

address

Parts (P)

pid

pname

color

Catalog (C)

sid

pid

cost

Page 11: Review

FUNCTIONAL DEPENDENCY

Page 12: Review

1212

FUNCTIONAL DEPENDENCIES (FDS)

A functional dependency XY holds over relation R if, for every allowable instance r of R: given two tuples in r, if the X values agree, then

the Y values must also agree. (X and Y are sets of attributes.)

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!

K is a candidate key for R means that KR However, KR does not require K to be minimal!

Page 13: Review

1313

EXAMPLE (CONTD.)

Problems due to R W : Update anomaly: Can

we change W in just the 1st tuple of SNLRWH?

Insertion anomaly: What if we want to insert an employee and don’t know the hourly wage for his rating?

Deletion anomaly: If we delete all employees with rating 5, we lose the information about the wage for rating 5!

S N L R W H

123-22-3666 Attishoo 48 8 10 40

231-31-5368 Smiley 22 8 10 30

131-24-3650 Smethurst 35 5 7 30

434-26-3751 Guldu 35 5 7 32

612-67-4134 Madayan 35 8 10 40

S 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 W

8 10

5 7Hourly_Emps2

Wages

Page 14: Review

1414

REASONING ABOUT FDS (CONTD.) Couple of additional rules (that follow from

AA): Union: If X Y and X Z, then X YZ Decomposition: If X YZ, then X Y and X Z

Example: Contracts(cid,sid,jid,did,pid,qty,value), and: C is the key: C CSJDPQV Project purchases a part using single contract:

JPC Dept purchases at most a part from a supplier:SD

P JP C, C CSJDPQV imply JP CSJDPQV SD P implies SDJ JP SDJ JP, JP CSJDPQV imply SDJ CSJDPQV

Page 15: Review

1515

Suppose that relation R contains attributes A1 ... An. A decomposition of R consists of replacing R by two or more relations such that: Each new relation scheme contains a subset of

the attributes of R (and no attributes that do not appear in R), and

Every attribute of R appears as an attribute of one of the new relations.

e.g., A B, ABCD E, EF GH, ACDF EG has the following minimal cover: A B, ACD E, EF G and EF H

Page 16: Review

1616

EXAMPLESA B C

1 2 3

4 2 3

5 3 3

5 3 4

Does A B hold? Don’t know

Does BC A hold? Does not hold (first two tuples)

Does B C hold? Does not hold (last 2 tuples)

Page 17: Review

1717

EXAMPLES Relation: ABCDE Dependencies:

A B C D

Decompose to?

Page 18: Review

1818

EXAMPLES Relation: ABCD Dependencies:

CD CA BC

What is the candidate key? B

Page 19: Review

1919

EXAMPLES Relation: ABCD Dependencies:

BC DA

What is the candidate key? BD

Page 20: Review

2020

EXAMPLES Relation: ABCD Dependencies:

ABCD DA

What is the candidate key? ABC BCD

Page 21: Review

2121

EXAMPLES Relation: ABCD Dependencies:

ABC ABD CA DB

What is the candidate key? AB BC CD AD

Page 22: Review

2222

EXAMPLES Suppose you are given a relation R(A,B,C,D) Dependencies

ABC CA CD

What is the candidate key? AB BC

Decomposed into ACD and BC. Good? Lossless. Can join back to ABCD. Dependency ABC is not preserved.

Page 23: Review

2323

EXAMPLES Suppose you are given a relation R(A,B,C,D) Dependencies

ABC CAD

What is the candidate key? A C

Decomposed into ABC and AD. Good? No. A is key, so no need to decompose. Dependency CAD is not preserved.