Docsity

Study Guide for Database Systems | EEL 4852C, Study notes of Deductive Database Systems

Toggle sidebar
bg1
DatabaseSystems#6–Summary09/11/08
Author:EduardSeibel
CoveredTopics
1.Theta,EQUI&NATURALJOIN
2.CompleteSetofR.A.Operations
3.DIVISIONOperation
4.GroupingwithAggregation
5.Queryexamples
1.Theta,EQUI&NATURALJOIN
• ThegeneralcaseoftheJOINoperationiscalledTheta‐JOIN
rθs=σθ(rxs)
Examples:Relation:rRelation:s
A B
α1
β 2
1. rA=CD<15s
2. r15*B<Ds
3. rA=Cs
• EQUIJOINisaJOINoperationwithequalitycomparsionsonly(seeexaple3.above)
• NATURALJOINjoinstworealtionsbyusingoverlappingattributes.Corresponding
attributeshavethesamenamesinbothrelations.ItisaimplizitJOINwithout
specifingexplicitlytheJOIN‐condition.
C DE
α10 a
β 10 a
β 20 b
γ 10 B
ABCDE
α 1α10 a
β 2β10 a
A BCDE
α1β20 b
ABCDE
α 1α10 a
β 2β10 a
β 2β20 b
pf3
pf4

Partial preview of the text

Download Study Guide for Database Systems | EEL 4852C and more Study notes Deductive Database Systems in PDF only on Docsity!

Database Systems #6 – Summary 09/11/

Author: Eduard Seibel

Covered Topics

  1. Theta, EQUI & NATURAL JOIN
  2. Complete Set of R. A. Operations
  3. DIVISION Operation
  4. Grouping with Aggregation
  5. Query examples 1. Theta, EQUI & NATURAL JOIN
    • The general case of the JOIN operation is called Theta‐JOIN

r θ s = σ θ ( r x s )

Examples: Relation: r Relation: s A B α 1 β 2

1. r A=C D < 15 s

2. r 15*B < D s

3. r A=C s

  • EQUI JOIN is a JOIN operation with equality comparsions only (see exaple 3. above)
  • NATURAL JOIN joins two realtions by using overlapping attributes. Corresponding attributes have the same names in both relations. It is a implizit JOIN without specifing explicitly the JOIN‐condition.

C D E

α 10 a β 10 a β 20 b γ 10 B

A B C D E

α 1 α 10 a β 2 β 10 a

A B C D E

α 1 β 20 b

A B C D E α 1 α 10 a β 2 β 10 a β 2 β 20 b

Example: Relation: r Relation: s A B C D α 1 α a β 2 γ a γ 4 β b α 1 γ a δ 2 β b

r * s ( = r r.B=s.B r.D=s.D s )

2. Complete Set of R. A. Operations

The set of operations including π (Projection), σ (Selection), – (Difference), ρ (Rename),

(Union) and x (Cartesian Product) is called a complete set, because any other R. A. expression can be expressed by combination of these five operations. (Slide 6 ‐44)

Example: Do we need Intersection? No, we can derive it from these five operations.

r s = ( r s ) ‐ ( r ‐ s ) ‐ ( s ‐ r )

3. DIVISION Operation

The devision operation is applied tot wo relations. R(Z) : S(X), where X is a subset of Z. Let Y

= Z ‐ Y (and hence Z = X Y); that is, let Y be the set of attributes of R that are not attributes of S.

The Result result of DIVISION is a relation T(Y) that includes a tuple t if tuples t R appear in R

with t R [Y] = t, and with t R [X] = t S for every tuple t s in S. (slide 6 ‐45)

B D E

1 a α 3 a β 1 a γ 2 b δ 3 b ξ

A B C D E

α 1 α a α α 1 β a γ α 1 γ a α α 1 γ a γ δ 2 β b δ

Theta JOIN

EQUI JOIN NATURAL JOIN

s

r

Examples: Relation r g SUM(C) (r) g SUM(C), COUNT(A) (r)

It is also possible to group the tuples by certain attributes first and then apply aggregate

operations.

Examples: we use the same realtion r (see above)

A g^ SUM(C) (r)^ A g^ SUM(C) (r)

5. Query examples

Query 1: Find all the names and addresses oft all the employees who work for the

‚Research‘ department.

π Fname, Minit, Lname, Address [ σ Dname=‘Research‘ (EMPLOYEE Dno = Dnumber

DEPARTMENT) ]

Query 2: Find all the names oft all employees who have no dependents.

π Fname, Minit, Lname [ ( π Ssn ( EMPLOYEE ) – π Essn ( Dependent ) ) * EMPLOYEE]

or

π Fname, Minit, Lname (EMPLOYEE) ‐ π Fname, Minit, Lname (EMPLOYEE Ssn =

Essn DEPENDENT)

A B C

α α 7 α β 7 β β 3 β β 10

SUM( C )

SUM( C ) COUNT( A )

A COUNT( C )

α 14 β 13

A B SUM( C )

α α 7 α β 7 β β 13