COM222 Test2 Marksheet

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CA - i

CA- ii
Eos
EoS-deferred

Question One: Introduction to Databases


1. Describe a database management system. (4)

[A software system that enables users to define (1), create (1), maintain (1), and control
access (1) to the database --4]
2. Explain how SQL provides physical and logical data independence.
(4)

[physical: the DDL does not specify how the records will be stored on disk, the file
structure and choice of index to be used (1). So as long as the schema in the DDL is
maintained, changes to storage details eg change in indexing algorithm, will not affect
applications using the schema except performance wise (1)

logical: DML - if a schema changes using a DDL, corresponding changes to the DML
can be made to obtain the same result for the user (1). This insulates the user from
noticing those changes (1)]

3. Define full functional dependency. (2)

[States that if A and B are attributes of a relation, B is fully functionally dependent on A


if B is functionally dependent on A BUT NOT on any proper subset of A -- 2]

COM222 Database Systems Page 2 of 5


Question Two: Relational Algebra
4. Specify relation algebra queries on the COMPANY relational database schema shown in
Figure 1 below. Also show the result of each query as it would apply to the database state
in Figure 1 below.
a. Retrieve the names of all employees who work on every project.
[[𝜋𝑙𝑛𝑎𝑚𝑒,𝑓𝑛𝑎𝑚𝑒 ( 𝑠𝑠𝑛 𝐹𝑐𝑜𝑢𝑛𝑡(𝑠𝑠𝑛)=(𝐹𝑐𝑜𝑢𝑛𝑡(∗) 𝑃) (𝐸 ⋈𝑠𝑠𝑛=𝑒𝑠𝑠𝑛 𝑊))

]
5. Consider the two tables 𝑇 and 𝑆 shown below.
T S
P Q R A B C
10 a 5 10 b 6
15 b 8 25 c 3
25 a 6 10 b 5

Show the result of the following operations:


a. 𝑇 ⋈𝑇.𝑃=𝑆.𝐴 𝒂𝒏𝒅 𝑇.𝑅=𝑆.𝐶 𝑆
[
P Q R A B C
10 a 5 10 b 5
]

Question Three: Practical


6. Using the Company relational Database Schema in Figure 1 below write an SQL
statement to retrieve:
a. The project number, the project name, and the number of employees who work on that
project. (4)
[SELECT Pnumber,Pname, COUNT (*)
FROM PROJECT, WORKS_ON
WHERE Pnumber=Pno
GROUP BY Pnumber, Pname;]
b. For each department that has more than five employees, the department number and the
number of its employees who are making more than K40,000
(5)
[SELECT Dnumber, COUNT (*) FROM DEPARTMENT, EMPLOYEE

COM222 Database Systems Page 3 of 5


WHERE Dnumber=Dno AND Salary>40000 AND Dnumber IN
( SELECT Dno FROM EMPLOYEE GROUP BY Dno
HAVING COUNT (*) > 5)]

FIGURE 1 COMPANY RELATIONAL DATABASE SCHEMA

Question Four: Functional dependencies and Normal forms

7. A first try to design a database for bookshop to track details of books sold by the
bookshop produced the schema, BOOKSHOP (Bookshop#, Bookshop_Addr, (BookNo,
BookTitle, BookAuthor, BookPublisher, Copies_Sold)). Assume that
Act[a,b,c(FK),(d,e)] represents a schema “Act” where a,b,..,e are attributes, (d,e)
represent a repeating group, c represent primary key and (FK) indicates attribute c is a
foreign key.

An instance of this schema is shown below


(6)
Bookshop Bookshop_Addr Book_No BookTitle BookAuthor BookPublisher Copies_Sold

COM222 Database Systems Page 4 of 5


Maneno Box 123, LL 1 MEC TDM Montfort Press 45
Update 9
Maneno Box 123, LL 2 Chitipa CM Likuni 8
Wenya
Claim Box 20, BT 3 Unofficial KGM Dzuka 12
Chanco Box 280, ZA 4 Nsanje ML Montfort Press 7
Central
Montfort P/Bag 3, BLK 1 MEC TDM Montfort Press 3
Update 9

a. Identify all the functional dependencies in the relation schema (3)

[FDS:
FD 1 BookNo → BookTitle, BookAuthor, BookPublisher
FD 2 Bookshop → Bookshop_Addr
FD 3 Bookshop, BookNo → Copies_sold --- 3 marks each FD

b. Normalise the table into 3rd Normal form. Show all the intermediate normal forms and
the functional dependencies defining the forms or otherwise. (11)

Question Five: Query optimisation

8. Consider the following relational algebra expressions:


i. πw((A ⋈x=y B) ⋈z=v C)
ii. πw((πv(C) ⋈v=z πwyz(B)) ⋈y=x A)
a. Translate the relational algebra expressions into their equivalent query trees (4)

[ ]
b. Assuming that (ii) is transformed from (i), Explain why query (ii) can be
considered to be more efficient than query (i) (4)
[The select operations (𝜋𝑣 ) and 𝜋𝑤𝑦𝑧 reduce the number of columns being carried
on to the join - 2
A more restricted relation A swapped with C in ii – 2 --- 4]

COM222 Database Systems Page 5 of 5

You might also like