hcs219 Assignment 2
hcs219 Assignment 2
Question one
The primary keys of each table are in bold. In the table Book the column number owned is the number
of copies of the book owned by the library, while the column number borrowed is the number of
copies currently out on loan. In table Borrowed the column person id is a foreign key into the Person
table, the column book id is a foreign key into the Book table. The column number is the number of
copies of the book borrowed by the associated person. (This library is used by primary school teachers
who frequently check out many copies of a book for the use in their classes.) If the database is
internally consistent, then the column number borrowed is redundant information that can be computed
from the actual number borrowed, and this can be derived from the Borrowed table.
(a) Write an SQL query that checks the internal consistency of this database. It should return records of
the form (book id, number borrowed, actual number borrowed) only for those books where number
borrowed and actual number borrowed are not equal. That is, if the database is consistent the query will
return no records. [5 marks]
(b) As a database administrator, redesign this schema so that there is no need for such consistency
checks. The first step is to design an Entity-Relationship model. This is done by introducing a new
entity called Copy Of. Each copy of a book owned by the library will be associated with a unique
member of the Copy Of entity. Design an Entity-Relationship diagram and show the cardinalities,
constraints in order to ensure that the database is internally consistent. [5 marks]
(c) State explain the advantage of a relational database model over other database models. [5 marks]
(d) Using one of your relational implementations from the previous part 1a), write an SQL query that
returns records of the form (book id, title, number owned, number borrowed). [5 marks]
Question two
Student(StudentNo, Firstname, Surname, Sex, Date of birth, Total fees paid, CourseID)
Course(CourseID, CourseName, StudentNo)
a. Consider the relational database schema given above. Write the SQL queries for the database above
to perform the following:
Database Administration is an important job carried out by a DBA (Database Administrator) that
involves managing and maintaining a database management system (DBMS). For the purpose of the
questions below, the DBA is responsible for managing a multi-use DBMS for a medium sized company
with up to 100 users at any one time.
a) Describe five tasks the DBA would need to carry out on a regular basis. [12 Marks]
b) Describe EACH of the following related pairs of concepts highlighting the association that exists
between them.
i. Availability and Integrity.
ii. Authorisation and Authentication [8marks]
Question 4
a. Describe, using a sequence of sample SQL statements, how the following key operations control the
processing of a database transaction:
I. SAVEPOINT; [2 marks]
II. COMMIT; [4 marks ]
III. ROLLBACK; [4 marks]
Question 5
The primary keys of each table are in bold. In the table Book the column number owned is the number
of copies of the book owned by the library, while the column number borrowed is the number of
copies currently out on loan. In table Borrowed the column person id is a foreign key into the Person
table, the column book id is a foreign key into the Book table. The column number is the number of
copies of the book borrowed by the associated person. (This library is used by primary school teachers
who frequently check out many copies of a book for the use in their classes.) If the database is
internally consistent, then the column number borrowed is redundant information that can be computed
from the actual number borrowed, and this can be derived from the Borrowed table.
(a) Write an SQL query that checks the internal consistency of this database. It should return records of
the form (book id, number borrowed, actual number borrowed) only for those books where number
borrowed and actual number borrowed are not equal. That is, if the database is consistent the query will
return no records. [5 marks]
(b) As a database administrator, redesign this schema so that there is no need for such consistency
checks. The first step is to design an Entity-Relationship model. This is done by introducing a new
entity called Copy Of. Each copy of a book owned by the library will be associated with a unique
member of the Copy Of entity. Design an Entity-Relationship diagram and show the cardinalities,
constraints in order to ensure that the database is internally consistent. [5 marks]
(c) State explain the advantage of a relational database model over other database models. [5 marks]
(d) Using one of your relational implementations from the previous part 1a), write an SQL query that
returns records of the form (book id, title, number owned, number borrowed). [5 marks]
Question 6
a. Great Zimbabwe University proposed a Relational database model that presents the database as a set
of relations. Define the following relational terms and comment on the differences between these terms
and the way that data is represented in a flat file.
i.Tuple;
ii.Attribute;
iii.Domain;
iv.Relation;
v.Primary Key. [5 marks]
b. Logical and Physical data independence is an important characteristic supported by a Relational
database system. Explain why Logical and Physical data independence is important.[5 marks]
c. Describe the ACID properties of transactions and explain why they are important in concurrency
control of a database. [10marks]
Question 7
a. Staff(name, position, branch number, branch address, telephone number, product items)
Normalise the above table for 1NF to 3NF and clearly explain each stage [12 marks]
Question 8
Consider the following two tables and answer the questions below:
Employee
Employee ID Name LastName DepName
1 Archie Blue Accounts
2 Allan Church Sales
3 Charlie Miller Customer Service
4 Archie Elephant Sales
5 Berta Archie
Department
DepName Manager
Accounts 1
Sales 4
Manager 3
a. Write the SQL Data Definition Statements to create the two tables above and choose suitable data
types. Ensure that suitable keys are defined for each entity.[10 marks]
b. Consider the following relational algebra queries and create matching SQL queries for the
Employee and Department tables:
I. Employee X Departments.
ii. ∏(Ω (name=archie)Employee) [5marks]
c. Define the term foreign key.List the properties of a foreign key. [5 marks]
Question 9
a. Describe the main recovery techniques that many DBMS (Database Management Systems) provide
to safeguard and protect data as a result of each of the following events:
IV. Human Error: an employee may unintentionally delete some data or may have used a routine
that has modified the data unknowingly in a way that would cease the DBMS from interacting
with the database effectively.[3 marks]
V. Network failure where a connection of a database to a shared network has been interrupted. [3]
VI. Media Failure with possible loss of all or some data.[3 marks]
VII. National catastrophe such as an earthquake or flood meaning the entire operation of the
host DBMS is lost.[3 marks]
VIII. Database software failure: this might be the result of the DBMS crashing expectantly.[3
marks]
b. Describe the security measures and precautions that a DBA (Database Administrator) must have in
place to prevent the database from being subject to hacking, for example, someone trying to steal data.
[5 marks]
Question 10
Database Administration is an important job carried out by a DBA (Database Administrator) that
involves managing and maintaining a database management system (DBMS). For the purpose of the
questions below, the DBA is responsible for managing a multi-use DBMS for a medium sized company
with up to 100 users at any one time.
a) Describe five tasks the DBA would need to carry out on a regular basis. [12 Marks]
b) Describe EACH of the following related pairs of concepts highlighting the association that exists
between them.
i.Availability and Integrity.
ii.Authorisation and Authentication [8marks]
Question 11
a. Normalise the Big Patient Table into 3rd normal form. The functional dependencies are shown in
Table 2 for your reference. Draw the functional dependency diagram, and show the result of each step
in the normalisation process:
Big Patient(Pat)(VisitNo, VisitDate, PatNo, PatAge, PatCity, ProvNo, ProvSpecialty, Diagnosis). [20
marks]
Question 12
a) Explain how a database management system differs from the file storage used in an operating system
such as Linux or Windows. [4 Marks]
b) Describe using examples EACH of the following terms and explain why they are important in a
database system: -
iii. Transaction.
iv. ANSI Standards.
v. Meta Data or Data Dictionary.
vi. Schema. [16 marks]