Docsity

Practice Problems for Assignment 2 | Database Systems | EEL 4852C, Assignments of Deductive Database Systems

Toggle sidebar
bg1
A.
Problem 2.5
a. Π
person
-
name
(
σcompany
-
name
= “First Bank Corporation” (
works
))
b. Π
person
-
name, city
(
employee
⋈
(
σcompany
-
name
= “First Bank Corporation” (
works
)))
c. Π
person
-
name, street, city
(
σ
(
company
-
name
= “First Bank Corporation”
∧ salary >
10000)
(
works
⋈
employee
))
d. Π
person
-
name
(
employee
⋈
works
⋈
company
)
e. Note: Small Bank Corporation will be included in each answer.
Π
company
-
name
(
company ÷
(Π
city
(
σcompany
-
name
=“Small Bank Corporation” (
company
))))
Problem 2.11
a.
t
1
←
Π
isbn
(
σpublisher
=“
McGraw−Hill
”(
books
))
Π
name
((
employee
⋈
loan
) ⋈
t
1))
b.
t
1
←
Π
isbn
(
σpublisher
=“
McGraw−Hill
”(
books
))
Π
name,isbn
(
employee
⋈
loan
)
÷ t
1
c.
t
1
←employee
⋈
loan
⋈ (
σpublisher
=“
McGraw−Hill
”(
books
))
Π
name
(
σcount
(
isbn
)
>
5 ((
empno Gcount−distinct
(
isbn
)(
t
1))))
d.
t
1
←employee
⋈
loan
⋈
books
Π
publisher,name
(
σcount
(
isbn
)
>
5 ((
publisher,empno Gcount−distinct
(
isbn
)(
t
1)))
Problem 3.9
a. select employee_name from works where company_name = ‘First Bank’;
b. select employee.employee_name, employee.street, employee.city
from employee, works, company
where employee.employee_name = works.employee_name AND
employee.city = company.city AND
company.company_name = works.company_name;
c. select T.employee_name, T.street_name, T.city
from employee T, employee S, manages
where T.employee_name = manages.employee_name AND
S.employee_name = manages.manager_name AND
T.street_name = S.street_name AND T.city = S.city;
d. The following solution assumes that all people work for at most one company.
select employee_name
from works T
where salary > (select avg (salary)
from works S
where T.company name = S.company name);
e. select company name
from works
group by company name
having sum (salary) <= all (select sum (salary)
from works
group by company name) ;
pf3

Partial preview of the text

Download Practice Problems for Assignment 2 | Database Systems | EEL 4852C and more Assignments Deductive Database Systems in PDF only on Docsity!

A.

Problem 2. a. Πperson- name ( σcompany- name = “First Bank Corporation” ( works)) b. Π person- name, city ( employee ⋈ ( σcompany- name = “First Bank Corporation” ( works))) c. Πperson- name, street, city ( σ( company- name = “First Bank Corporation” ∧ salary > 10000) ( works ⋈ employee)) d. Π person- name ( employee ⋈ works ⋈ company) e. Note: Small Bank Corporation will be included in each answer. Πcompany- name ( company ÷ (Πcity ( σcompany- name=“Small Bank Corporation” ( company))))

Problem 2.

a. t 1 ←Π isbn( σpublisher=“ McGraw−Hill ” ( books)) Π name(( employee ⋈ loan) ⋈ t 1 )) b. t 1 ←Π isbn( σpublisher=“ McGraw−Hill ” ( books)) Π name,isbn( employee ⋈ loan) ÷ t 1 c. t 1 ←employee ⋈ loan ⋈ ( σpublisher=“ McGraw−Hill ” ( books)) Π name ( σcount( isbn) > 5 (( empno Gcount−distinct( isbn)( t 1 )))) d. t 1 ←employee ⋈ loan ⋈ books Π publisher,name ( σcount( isbn) > 5 (( publisher,empno Gcount−distinct( isbn)( t 1 )))

Problem 3.

a. select employee_name from works where company_name = ‘First Bank’;

b. select employee.employee_name, employee.street, employee.city from employee, works, company where employee.employee_name = works.employee_name AND employee.city = company.city AND company.company_name = works.company_name ;

c. select T.employee_name, T.street_name, T.city from employee T, employee S, manages where T.employee_name = manages.employee_name AND S.employee_name = manages.manager_name AND T.street_name = S.street_name AND T.city = S.city ;

d. The following solution assumes that all people work for at most one company.

select employee_name from works T where salary > ( select avg ( salary ) from works S where T.company name = S.company name );

e. select company name

from works group by company name having sum ( salary ) <= all ( select sum ( salary ) from works

group by company name ) ;

Problem 3.

a. select distinct A from r; b. select * from r where B = 17 c. select distinct * from r , s d. select distinct A, F from r , s where C = D

Problem 3.

a. ( select * from r 1) union ( select * from r 2)

b. We can also write this using the intersect operation. select * from r 1 where (A, B, C) in ( select * from r 2)

c. select ∗ from r 1 where (A, B, C) not in ( select ∗ from r 2) This can also be solved using the except clause.

d. select r 1 .A , r 2 .B , r 2 .C from r 1, r 2 where r 1 .B = r 2 .B

Problem 3.

a. select name from employee e , books b , loan l where e.empno = l.empno and l.isbn = b.isbn and b.publisher = ’McGrawHill’

b. select distinct e.name from employee e where not exists (( select isbn from books where publisher = ’McGrawHill’) except ( select isbn from loan l where l.empno = e.empno ))

c. select publisher , name from ( select publisher , name , count isbn from employee e , books b , loan l where e.empno = l.empno and l.isbn = b.isbn group by publisher , name ) as emppub(publisher, name, count books) where count books > 5

B.

a.

c 11.

b 7