The Relational Model and Relational Algebra · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Asking questions with sets of rows

Computing · Data & Databases · ages 18-19
Name ______________________   Date ____________
  1. Students has name and age attributes. In π_name(σ_age>10(Students)), which operation acts first?

    • Project names first, then test the removed age attribute
    • Run both operations together without an intermediate relation
    • Select by age, then project names
  2. R has attributes id, name and course. What is the result schema of π_id,course(R)?

    • id, name and course
    • id and course
    • name and course only
    • id and name only
  3. R(a,b) = {(1,4),(2,5)}. Which display contains exactly the same relation?

    • S(a,b) = {(4,1),(5,2)}
    • S(a,b) = {(1,4),(2,6)}
    • S(a,b) = {(2,5),(1,4)}
    • S(a,b) = {(1,4),(2,5),(3,6)}
  4. Which sentence describes a relation in the mathematical relational model?

    • A set of tuples over named attributes
    • A list of values whose row positions define identity
    • A collection of rows with no fixed set of attributes
  5. Compatible relations R and S share 2 of R's 4 tuples. How many tuples are in R - S?

    Answer: ______________

  6. Students(id,name,age) and Enrolled(id,course) share only id. Which expression returns name/course pairs for enrolled students over 21? Here ⋈ is natural join.

    • π_name,course(σ_age>21(Students) ⋈ Enrolled)
    • π_name,course(Students ⋈ Enrolled), retaining students of every age
    • π_name,course(π_name(Students) ⋈ Enrolled), removing the matching id
    • π_name,course(Students ∪ Enrolled), pooling the different schemas
  7. Compatible relations R and S contain 6 and 5 tuples. Exactly 3 tuples occur in both. How many tuples are in R ∪ S?

    Answer: ______________

  8. R(id,name) = {(10,Uma),(11,Uma),(12,Sol)}. How many tuples are in π_name(R) under pure relational algebra?

    • 2 tuples
    • 3 tuples
    • 1 tuple
    • 0 tuples
  9. Students(id,age) and Enrolled(id,course) share only id. Which expression always equals σ_age>21(Students ⋈ Enrolled)?

    • Students ⋈ σ_age>21(Enrolled), testing age in the enrollment input
    • π_id(σ_age>21(Students)) ⋈ Enrolled, removing age from the result
    • σ_age>21(Students) ⋈ Enrolled
    • σ_age>21(Students) ∪ Enrolled, replacing matching pairs with union
  10. R(a,b) = {(2,7)} and S(a,b) = {(2,9)}. Kim claims π_a(R ∩ S) = π_a(R) ∩ π_a(S). Why does this example disprove the claim?

    • Intersection cannot compare tuples containing more than one attribute
    • Projection hides the differing b values and creates a shared a value
    • Projection changes the original a values before comparing their membership
LightMySky · lightmysky.comW1-mt_unDBd_Ug8T-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Asking questions with sets of rows W1-mt_unDBd_Ug8T-s1

  1. Select by age, then project names · The inner selection receives Students first. Projection then retains the names from the surviving rows.
  2. id and course · Projection retains exactly its named attributes: id and course. It removes name.
  3. S(a,b) = {(2,5),(1,4)} · The matching display contains the same complete tuples under the same attributes. Only their written order changes.
  4. A set of tuples over named attributes · A relation has named attributes and a set of tuples. Each distinct tuple appears once, without a meaningful row order.
  5. 2 · Remove the 2 shared tuples from R's 4 tuples: 4 - 2 = 2.
  6. π_name,course(σ_age>21(Students) ⋈ Enrolled) · Filter while age is available, join enrollment using id, then project the required name and course attributes.
  7. 8 · Adding 6 + 5 counts the shared tuples twice. Subtract their 3 extra counts: 11 - 3 = 8.
  8. 2 tuples · Dropping id makes the two Uma tuples identical. The projected relation contains (Uma) and (Sol).
  9. σ_age>21(Students) ⋈ Enrolled · The age test uses only Students attributes. Filtering that input first retains exactly the same matching pairs and output attributes.
  10. Projection hides the differing b values and creates a shared a value · The full tuples differ, so the left result is empty. Both projections contain 2, so the right result contains 2.
Worksheet · LightMySky