23000483-CS237 Assignment-1-1
23000483-CS237 Assignment-1-1
ASSIGNMENT-1
1. Consider the relational database of Figure 3.39, where the primary keys are underlined.
employee (person-name, street, city)
works (person-name, company-name, salary)
company (company-name, city)
manages (person-name, manager-
name)
Figure 3.39
Give an expression in the relational algebra to express each of the following queries:
a.Find the names of all employees who work for First Bank Corporation.
b.Find the names and cities of residence of all employees who work for First Bank
Corporation.
c.Find the names, street address, and cities of residence of all employees who work for
Aryan 23000483
First Bank Corporation and earn more than $10,000 per annum.
d.Find the names of all employees in this database who live in the same city as the
company for which they work.
e.Find the names of all employees in this database who do not work for First Bank
Corporation.
f.Find the names of all employees who live in the same city and on the same street as do
their managers.
g.Find the names of all employees who earn more than every employee of Small Bank
Corporation.
h. Assume the companies may be located in several cities. Find all companies located in
every city in which Small Bank Corporation is located.
2. Give an SQL DDL definition for relational database of Figure 3.39. Define appropriate
primary key and foreign key for each relation schema and include them in DDL
Definition.
Answer:
city varchar(255)
);
city varchar(255)
);
company_name varchar(255),
);
person_name varchar(255),
manager_name varchar(255),
);
Suppose that we wish to require that every eid (represents employee id) that appears in
either salaried_worker or hourly_worker, must refer some tuple in employee.
Give a DDL Definition in SQL for expressing such referential integrity constraints.
Discuss the actions that the system must take to enforce a constraint of this form.
Answer:
If eid is a key for the employee relation, could it be a key for the salaried_worker relation
and hourly_worker relation? Justify your answer.
Answer:
if eid is key for employee relation, it can be key for both salaries_worker and
hourly_worker relations, provided that each worker type in uniquely by eid. This is
because eid must uniquely each employee in all relations.
Shipment (s#, p#, qty) à primary key: s#, p#, foreign key: s# references suppliers(s#), p#
reference Parts(p#)
Find the s# of suppliers who supply red part or are located in london.
Find the s# of suppliers who supply red part and green part.
Find the s# who supply at least all those parts supplied by supplier s2.
ρ.Suppliers𝜌.Suppliers
Answer: π suppliers.sname(π suppliers. City = s.city (suppliers
6. Consider the relational Database given in previous example Suppliers, parts and
shipments. Here, s# is a key to the relation suppliers, p# is a key to the relation parts. The
foreign-key clause requires that every s# in shipment refers s# in suppliers and p# in
Aryan 23000483
shipment refers p# in parts. Explain exactly what happens when a tuple in the relation
supplier or parts is deleted. Justify your answer.
Answer:
Effect of Deleting a Supplier or Part:
In our database, the Suppliers (s#), Parts (p#), and Shipments (s#, p#, qty) tables are
connected through foreign keys.
7. Consider the database of a sailing club with the following three tables:
Sailor(sid: integer, name: string, rating: integer, age: integer)
Identify primary keys in above relations. Write the following queries in relational algebra.
Find the names of sailors who have reserved all red boats
Find the name and age of all sailors with a rating above 7
Find the names of sailors with a rating greater 5 and an age > 30.
Find the rating and the age of the sailors who reserved a red boat.
Find the IDs of those sailors who reserved the boat ‘Clipper’ and who reserved a green
boat.
Find the IDs of those sailors who has not reserved a red boat.
List the IDs of those sailors who has reserved all boats
List the ids of those sailors who has reserved all red boats.
Find the names of members who have borrowed any book published by “McGraw-Hill”.
Find the name of members who have borrowed all books published by “McGraw-Hill”.
(books))) ⋈ member)
Answer: π name((π memb_no, isbn(borrower) ÷ σ isbn(σ publisher=’McGraw-Hill’
Find the name and membership number of members who have borrowed more than five
different books published by “McGraw-Hill”.
For each publisher, find the name and membership number of members who have
borrowed more than five books of that publisher.
Find the average number of books borrowed per member. Take into account that if a
member does not borrow any books, then that member does not appear in the borrowed
relation at all.
Find the names of members who borrowed a book titled "Database Systems"
Find the members who have borrowed the book "Data Structures"
9. The constraint that values of a given foreign key must match values of the
corresponding primary key is known as a .
Answer: for every value of foreign key in table, there must exist matching value in
corresponding primary key of referenced table, or foreign key value must be null.
14 Which of the following operators are unary operators? (Select multiple correct answers if
. exists)
Select (σ)
Project (∏)
Rename (ρ)
Cross Product (X)
I & III
I & II
I, II & III
RUS
R–S
R∩S
17. Consider two relations r (R) and s(S). The natural join of r and s, denoted by r ⋈ s, can be
defined as:
Please note that if r (R) and s(S) are relations without any attributes in common, that is, R
∩ S = ∅, then r ⋈ s = r ⋈ s = r × s
If R ⋈ S is applied, then
20. Consider the Banking enterprise example discussed in class. Answer the following:
Find the names of all customer who have both a loan and an account at the bank.
Which of following query generates the correct answer:
πcustomer-name (borrower) intersection πcustomer-name (depositor)
customer-name(borrower ⋈ depositor))
I & IV only
21. Consider the Banking enterprise example discussed in class. Consider the following
relational algebra query.
account) r2 ÷ r1
Aryan 23000483
Answer:
r2: it is table listing customer names and the branch names of their accounts.
r3: it gives customer names of those who have accounts at all Brooklyn branches.
23. List four significant problems of a file-processing system that prompted the development
of a DBMS.
Answer:
Data isolation
Answer:
26. Describe the differences in meaning between the terms relation and relation schema.
Answer:
Value is unknown at time of data entry for example new employee’s phone number is not
provided yet.
Attributes does not apply to particular record for example middle name for person who
does not have one
28. True / False In Relational Model, for all relations r, the domains of all attributes of r be
atomic. What does it mean? Explain your answer with example.
Answer:
True
In relational model, each attributes should atomic values, meaning no multiple values or
nested in single field.
Irreducibility Property)
a & b both
31. Given the two relations R(A,B,C) and S(B,C,D). Answer which all attributes and tuples
will be included in the output considering each of the following cases. Support your
answer with example.
Answer:
Output:
A B C D
1 x y p
2 z w q
Answer:
Answer:
A B C B D
1 x y x p
2 z w z q
Answer:
A B C D
1 x y p
2 z w q
Answer:
A B C D
Aryan 23000483
1 x y p
2 z w q
Answer:
A B C D
1 x y p
2 z w q
32. Given relations R(A, B) and S(A, C), the natural join R ⋈ S is equal to R ∩ S.
True B. False
Answer: False
33. Given relations R(A, B, C) and S(D, E), the natural join R ⋈ S is equal to R × S.
True B. False
Answer: True
34. It is possible to express the relational algebra operator intersection ( ∩ ) using the
difference operator ( − ).
True B. False
Answer: True