Relational Algebra Cheat Sheet PDF [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Relational Algebra: Selection (σ): Selects tuples that satify certain conditions. Operators:​ −, =, ≠, ≥, , ≤ Connectors:​ ​and​, ​or​, n ​ ot

Projection (π): Projects a subset of a table’s columns. π​ btag, first_name (Bird) — Projects the tag and first name of all Birds ​

σ​ sentiment > 0.9 (Chirp) — Selects Chirps with sentiment less than 0.9. ​ σ​ last_name = 'Trump' ​(Bird) — Selects Birds whose last name is Trump. *Cross-Product (×): Combines two relations with every possible combination of tuples.

*Difference (−): Selects tuples that are present in one relation but not the other.

*Union (∪): Selects tuples that are present in both relations.

Natural Join (⋈): Combines two relations by finding a common attribute between them

Conditional Join (⋈​C​): Combines two relations similar to cross product but with a condition

Division (÷): Reduces a relation by performing the opposite of a cartesian product

*Must be union compatible:

1) Same number of columns

Relational Calculus [Examples]: Sailors(sid, sname, rating, age), 1. 2. 3.

2) Corresponding columns are of the same variable type

Reserves(sid, bid, date),

Boats(bid, bname, color)

Find sailors with a rating > 7 {s | s ∈ S ailors ⋀ s.rating > 7} Find names of sailors who’ve reserved a red boat {t(sname) | ∃s ∈ S ailors(t.sname = s.sname ⋀ ∃r ∈ Reserves(r.sid = s.sid ⋀ ∃b ∈ B oats(b.bid = r.bid ⋀ b.color = ′red′)))} Find the names of sailors who’ve reserved all “Interlake” boats {t(sname) | ∃s ∈ S ailors(t.sname = s.sname ⋀ ∀b ∈ B oats(b.bname = ′Interlake′ → (∃r ∈ Reserves(r.sid = s.sid ⋀ b.bid = r.bid))))}

MySQL: Queries: SELECT ● DISTINCT ● T.attr, T.attr ​as​ attribute ● COUNT​(*) ● MAX​(T.attr), ​MIN​(T.attr), ​AVG​(T.attr) FROM ● Table T ● Table2 T2 WHERE ● =, !=, >, =,