100% found this document useful (1 vote)
2K views3 pages

Relational Algebra Exanples

The document describes a relational database schema called Pubs with tables for authors, publications, and books. It provides sample data and exercises involving relational algebra queries against the Pubs tables. The exercises ask the user to write queries and determine results and semantics of given queries involving joins, projections, differences and selections on the Pubs tables.

Uploaded by

hweoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views3 pages

Relational Algebra Exanples

The document describes a relational database schema called Pubs with tables for authors, publications, and books. It provides sample data and exercises involving relational algebra queries against the Pubs tables. The exercises ask the user to write queries and determine results and semantics of given queries involving joins, projections, differences and selections on the Pubs tables.

Uploaded by

hweoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Relational Algebra Exercises

Pubs Database Schema


author(author id, f irst name, last name)

author pub(author id, pub id, author position)

book(book id, book title, month, year, editor)

pub(pub id, title, book id)

• author id in author pub is a foreign key referencing author


• pub id in author pub is a foreign key referencing pub

• book id in pub is a foreign key referencing book


• editor in book is a foreign key referencing author(author id)
• Primary keys are underlined

Pubs Database State


r(author) r(author pub)
author id first name last name author id pub id author position
1 John McCarthy 1 1 1
2 Dennis Ritchie 2 2 1
3 Ken Thompson 3 2 2
4 Claude Shannon 4 3 1
5 Alan Turing 5 4 1
6 Alonzo Church 5 5 1
7 Perry White 6 6 1
8 Moshe Vardi
9 Roy Batty

r(book) r(pub)
book id book title month year editor pub id title book id
1 CACM April 1960 8 1 LISP 1
2 CACM July 1974 8 2 Unix 2
3 BST July 1948 2 3 Info Theory 3
4 LMS November 1936 7 4 Turing Machines 4
5 Mind October 1950 NULL 5 Turing Test 5
6 AMS Month 1941 NULL 6 Lambda Calculus 6
7 AAAI July 2012 9
8 NIPS July 2012 9

Figure 1: Relational Database Schema


1. How many tuples will be returned by the following relational algebra query?

πbook title (book)

Solution: 2

2. What question does the following expression answer?

|πauthor id (author) − πeditor (book)|

Solution: How many authors are not book editors.

3. Write a relational algebra expression that returns the names of all authors who are book editors.

Solution: πf irst name,last name (author ./author id=editor book)

Page 2
4. Write a relational algebra expression that returns the names of all authors who are not book editors.

Solution: πf irst name,last name ((πauthor id (author) − πeditor (book)) ∗ author)

5. Write a relational algebra expression that returns the names of all authors who have at least one publi-
cation in the database.

Solution: πf irst name,last name (author ∗ author pub)

6. How many tuples are returned by the following relational algebra expression?

author ./author id=editor book

Solution: 11

7. What question does the following relational algebra expression answer?

author ∗ (author pub ∗ (σmonth=0 July0 (book) ∗ pub))

Solution: Which authors authored a pub that was published in July?

Page 3

You might also like