CIT843
CIT843
Question 1
a. i. What is a Primary Key? State the rules for defining primary ke: (3.5marks)
ii. What is Candidate Key? Differentiate between a Candidate and Alternative Key and state
the properties for each.
(6 marks)
iii. From the Table below, identify the primary key, Candidate Key and the Alternate key
(3 marks)
b. i. When do we need to store derivable data in the table and what are the advantages
and disadvantages of storing derivable data in a table? (4marks)
ii. Apart from containing sequences of SQL code in a script, describe other ways that SQL
code can be stored, contained, encapsulated and run as a sequence of executable
statements (2.5 marks)
iii. Describe four possible benefits of “Views” in databases. (2 marks)
c. Define the basic characteristics of a NoSQL database, with examples of
where is used (2 marks)
d. Explain how the entity relationship (ER) model helped produce a more structured
relational database design environment (2 marks)
Question 2
a. The following table stores details of employees and the projects they work on and for how
long. The Primary Key is (EmpID, ProjID).
Explain why the above table is not in 2nd Normal Form.
Transform the table into 2nd Normal Form tables. (6 marks)
b. Using your own specific examples, illustrate the following SQL querying techniques:
i. Row-level filtering.
ii. Aggregate functions.
iii. Grouping and group-level filtering.
iv. Joining.
v. Sub-Queries.
(5marks)
c. A football club uses the table below to record details of players and the positions in which
they can play. Each player can play in up to a maximum of three positions:
i. Explain why this table is not in “First Normal Form” (1NF). (1 mark)
ii. Show how this table can be transformed into 1NF tables. Give 2 possible solutions.
(3 marks)
Question 3
a.. i. With reference to the table below explain the concept of a Domain.
ii. List 2 examples from the above tables of columns that could be defined as a
domain.
iii. Suppose you were required to implement (create and populate) in the tables using
an SQL script containing a set of CREATE TABLE and INSERT operations.
List the logical sequence the tables should be populated to ensure referential
integrity is preserved.
iv. TotalQtySold is a column that contains derived data. Write a SQL SELECT
statement that computes a value for this column for a specific product.
v. When do we need to store derivable data in the table and what are the advantages
and disadvantages of storing derivable data in a table?
vi. Write an SQL UPDATE statement that updates the column TotalQtySold given
a specific product.
i. With reference to the table explain the concept of a Domain. (2marks)
ii. List 2 examples from the tables of columns that could be defined as a domain. (2marks)
iii. Suppose you were required to implement (create and populate) in the tables using an SQL
script containing a set of CREATE TABLE and INSERT operations.
List the logical sequence the tables should be populated to ensure referential
integrity is preserved. (2marks)
iv. TotalQtySold is a column that contains derived data. Write a SQL SELECT
statement that computes a value for this column for a specific product.
(4marks)
vi. Write an SQL UPDATE statement that updates the column TotalQtySold given
a specific product. ( 5marks)
Question 4
Assume the following SQL script is to be executed:
CREATE TABLE Students (StudentID CHAR(6)
,StudentFname VARCHAR(20) NOT NULL
,StudentLname VARCHAR(20) NOT NULL
,Date_of_Birth DATE
,CourseCode CHAR(6) ,
CONSTRAINT student_pk PRIMARY KEY (Studentid));
a. Classify TWO types of data integrity checks that have been specified to prevent invalid
data being entered. Give examples of each of these types of data integrity checks.
(2marks)
ii. What is the result of running the above script (assuming it is syntactically correct) in terms
of table creation and insertion of data? (2.5 marks)
iii. Change the script to enforce an additional constraint that would be applied to restrict
the data of birth of all students to be later than 01-jan-1998. (2marks)
iv. Change the script to enforce an additional constraint that would ensure data integrity
between data referenced in both the Students and Courses Tables. Assume that a student
can only attend one course at a time and a course may have many students (3marks)
vi. Why is it necessary to constrain updates performed on referenced data in tables such as
Courses and Students? Explain the measures available in SQL to constrain these updates.
(2marks)
vii. Describe with the aid of example SQL code how data may be inserted into a table by
selecting and copying data from one or more existing tables, hence avoiding the use
of many INSERT statements (3.5 marks)
Question 5
Consider the following relations:
Doctor(SSN, FirstName, LastName, Specialty, YearsOfExperience, PhoneNum)
Patient(SSN, FirstName, LastName, Address, DOB, PrimaryDoctor_SSN)
Medicine(TradeName, UnitPrice, GenericFlag)
Prescription(Id, Date, Doctor_SSN, Patient_SSN)
Prescription_Medicine(Prescription Id, TradeName, NumOfUnits)
The Doctor relation has attributes Social Security Number (SSN), first and last names, specialty, the
number of experience years, and the phone number.
The Patient relation has attributes SSN, first and last names, address, date of birth (DOB), and the
SSN of the patient’s primary doctor.
The Medicine relation has attributes trade name, unit price, and whether or not the medicine is
generic (True or False).
The Prescription relation has attributed the prescription id, the date in which the prescription is
written, the SSN of the doctor who wrote the prescription, and the SSN of the patient to whom the
prescription is written.
The Prescription Medicine relation stores the medicines written in each prescription along with
their quantities (number of units).
iii. List the first and last name of doctors who are not primary doctors to any patient (2 marks)
iv.. For medicines written in more than 20 prescriptions, report the trade name and the total number of
units prescribed (2 marks)
v. List the SSN of patients who have ʻAspirinʼ and ʻVitaminʼ trade names in one prescription (3 marks)
vi. List the SNN of distinct patients who have ʻAspirinʼ prescribed to them by doctor named ʻJohn
Smithʼ (3 marks)
vii. List the first and last name of patients who have no prescriptions written by doctors other than their
primary doctors. (3 marks)