Docsity

Solved Questions for Homework 2 - Database Systems | CS 430, Assignments of Deductive Database Systems

Toggle sidebar
bg1
Homework 2 Solution
February 25, 2009
Q1: Min and Max sizes. 10 points
1. Max: N1+N2, N1 has no shared tuples as N2. Min: N2, R1 is a subset of R2.
2. Max: N1, R1 is a subset of R2. Min: 0, no common tuples.
3. Max: N1, no common tuples. Min: 0, R1 is a subset of R2.
4. Max: N1 ×N2, Min: N1 ×N2.
5. Max: N1, one field called ’a’ in all tuples contains value 5. Min: 0.
6. Max: N1. Min: 0,’a’ is not a field name of R1.
7. Max: N1, suppose R1 (X, Y) and R2 (Y,Z). In R1, X is the primary key (unique
values) Y is also unique; in R2, X is the primary key (unique values) Y is also
unique and equal to Y value of R1. Min: 0 R1 and R2 has no common fields.
Q2: a) b) c)
1. Q2.a) 65 points
(a) Find the names of all employees who work for First Bank Corporation.
i. Πperson_name (σcompany_name=Fir stBankCor p (works))
ii. {p|∃w∈works(p.per son_name =w.per son_name∧w.company_name =
Fir stBankC orp)}
iii. {hperson_namei|∃v(hper son_name,0First BankCor p0,vi∈work s)}
(b) Find the names and cities of residence of all employees who work for First
Bank Corporation
i. Πperson_name,city em ployee ./ (σcompany_name=Fir stBankC orp (works))
ii. {p|∃w∈works(∃e∈em ployee(w.com pany_name =Fir st BankCor p∧
p.person_name =w.per son_name∧e.per son_name =w.person_name∧
p.city =e.city))}
iii. {hperson_name,cityi|∃v1(hper son_name,v1,cityi∈em ployee)
∧∃v2(hperson_name,F irstBankCor p,v2i∈works)}
1
pf3

Partial preview of the text

Download Solved Questions for Homework 2 - Database Systems | CS 430 and more Assignments Deductive Database Systems in PDF only on Docsity!

Homework 2 Solution

February 25, 2009

Q1: Min and Max sizes. 10 points

  1. Max: N1+N2, N1 has no shared tuples as N2. Min: N2, R1 is a subset of R2.
  2. Max: N1, R1 is a subset of R2. Min: 0, no common tuples.
  3. Max: N1, no common tuples. Min: 0, R1 is a subset of R2.
  4. Max: N1 × N2, Min: N1 × N2.
  5. Max: N1, one field called ’a’ in all tuples contains value 5. Min: 0.
  6. Max: N1. Min: 0,’a’ is not a field name of R1.
  7. Max: N1, suppose R1 (X, Y) and R2 (Y,Z). In R1, X is the primary key (unique values) Y is also unique; in R2, X is the primary key (unique values) Y is also unique and equal to Y value of R1. Min: 0 R1 and R2 has no common fields. Q2: a) b) c)
  8. Q2.a) 65 points

(a) Find the names of all employees who work for First Bank Corporation. i. Πperson_name(σcompany_name=FirstBankCorp(works)) ii. {p|∃w ∈ works(p.person_name = w.person_name∧w.company_name = FirstBankCorp)} iii. {〈person_name〉 |∃v(〈person_name,′^ FirstBankCorp′, v〉 ∈ works)} (b) Find the names and cities of residence of all employees who work for First Bank Corporation i. Πperson_name,city

employee ./ (σcompany_name=FirstBankCorp(works))

ii. {p|∃w ∈ works(∃e ∈ employee(w.company_name = FirstBankCorp∧ p.person_name = w.person_name∧e.person_name = w.person_name∧ p.city = e.city))} iii. {〈person_name, city〉 |∃v1(〈person_name, v 1 , city〉 ∈ employee) ∧∃v2(〈person_name, FirstBankCorp, v 2 〉 ∈ works)}

(c) Find the names, street address, and cities of residence of all employees who work for First Bank Corporation and earn more than $100,000 per annum. i. Πperson_name,street,city(employee ./ (σcompany_name=FirstBankCorp∧salary> 100000 (works))) ii. {p|∃w ∈ works(∃e ∈ employee(w.companyname = FirstBankCorp ∧ w.salary > 100000 ∧p.person_name = w.person_name∧e.person_name = w.person_name ∧ p.city = e.city ∧ p.street = e.street))} iii. {〈person_name, street, city〉 | 〈person_name, street, city〉 ∈ employee ∧∃y(〈person_name, FirstBankCorp, y〉 ∈ works) ∧ y > 100000)} (d) Find the names of all employees in this database who live in the same city as the company for which they work. i. Πperson_name(employee ./ works ./ company) ii. {p|∃e ∈ employee(∃c ∈ company(∃w ∈ works(w.company_name = c.company_name∧p.person_name = e.person_name∧e.person_name = w.personname ∧ e.city = c.city)))} iii. {〈person_name〉 |∃company_name, salary(〈person_name, company_name, salary〉 ∈ works(∃c, v(〈company_name, c〉 ∈ company ∧ 〈person_name, v, c〉 ∈ employee)))} (e) Find the names of all employees in this database who live in the same city as the company for which they work. i. and ii and iii Same as above... (f) Find the names of all employees who live in the same city and on the same street as do their manager. i. Πperson_name(σmanages.manager_name=employee 2 .person_name∧employee.street=employee 2 .street ∧employee.city=employee 2 .city(manages^ ./^ employee^ ./ ρ(employee^2 ,^ employee))) ii. {p|∃e ∈ employee(∃m ∈ employee(∃r ∈ manages(r.person_name = e.person_name ∧ r.manager_name = m.person_name) ∧ e.city = m.city ∧ e.street = m.street ∧ p.person_name = e.person_name))} iii. {〈p〉 |∃m(〈p, m〉 ∈ manages ∧ ∃s, c(〈p, s, c〉 ∈ employee ∧ 〈m, s, c〉 ∈ employee)} (g) Find the names of all employees in this database who do not work for First Bank Corporation. i. Πperson_name(σcompany_name,FirstBankCorp(works)) ii. {p|∃w ∈ works(w.company_name ,′^ FirstBankCorp′∧p.person_name = w.person_name)} iii. {〈person_name〉 |∃c, s(〈person_name, c, s〉 ∈ works∧¬(∃sa(〈person_name, FirstBankCorp, sa〉 ∈ works)))}

  1. Q2.b) 15 points

(a) employee ← Πperson_name,street,Newton(σperson_name=Jones(employee))∪(σperson_name,Jones(employee)) (b) works ← Πperson_name,company_name,salary∗ 1. 1 (σcompany_name=′^ FirstBankCorp′^ (works))∪ (σcompany_name,′^ FirstBankCorp′^ (works))