Relational Algebra Excercises, Exercises of Algebra

Pubs Database Schema,Pubs Database State and With Solutions.

Typology: Exercises

2021/2022

Uploaded on 02/11/2022

jamal33
jamal33 🇺🇸

4.3

(51)

340 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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

Partial preview of the text

Download Relational Algebra Excercises and more Exercises Algebra in PDF only on Docsity!

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) author id first name last name 1 John McCarthy 2 Dennis Ritchie 3 Ken Thompson 4 Claude Shannon 5 Alan Turing 6 Alonzo Church 7 Perry White 8 Moshe Vardi 9 Roy Batty

r(author pub) author id pub id author position 1 1 1 2 2 1 3 2 2 4 3 1 5 4 1 5 5 1 6 6 1

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

r(pub) 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)

Solution: 7

  1. What question does the following expression answer?

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

Solution: How many authors are not book editors.

  1. 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