Relational Algebra
Pubs Database Schema
author(author id, first 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(pub)
r(book)
book id book title month year editor
1 CACM April 1960 8
2 CACM July 1974 8
3 BST July 1948 2
4 LMS November 1936 7
5 Mind October 1950 NULL
6 AMS Month 1941 NULL
7 AAAI July 2012 9
8 NIPS July 2012 9
pub id title book id
1 LISP 1
2 Unix 2
3 Info Theory 3
4 Turing Machines 4
5 Turing Test 5
6 Lambda Calculus 6
Figure 1: Relational Database Schema
1. How many tuples will be returned by the following relational algebra query?
πbook title(book)
1. What question does the following expression answer?
|πauthor id(author) − πeditor(book)|
2. Write a relational algebra expression that returns the names of all authors who are book editors.
3. Write a relational algebra expression that returns the names of all authors who are not book editors
4. Write a relational algebra expression that returns the names of all authors who have at least one
publication in the database.
author ∗ (author pub ∗ (σmonth='July' (book) ∗ pub))
5. What question does the above relational algebra expression answer?
6. How many tuples are returned by the above relational algebra expression?