You are on page 1of 4

CA - i

CA- ii
1. Introduction to Databases
a. Describe a database? (4)
[A shared collection (1) of logically related data (1) and its description (1),
designed to meet the information needs of an organization (1) --4]
b. How many distinct tuples are in a relation instance with cardinality 4,785? (2)
c. What is the difference between a super, candidate and primary key for a given relation?
(5)

[Super key: set of fields that uniquely identifies a tuple according to a key constraint
Candidate key: minimal set of fields that uniquely identifies a tuple according to a key
constraint - 2
Primary key: is a chosen candidate key among the many in a relation (1) that a DBMS
expects, prefers and optimizes to make references to tuples in the relation (2) -- 3]
d. Describe two major components of SQL. (4)

[DDL: Data definition language – statements used to create the DB structure and define
access mechanism – 2
DML: Data manipulation language – statements used to populate and query the tables –
2 --- 4]
e. What is the difference between a subquery (or nested query) and a join. Under what
circumstances would you not be able to use a subquery? (3)

[Subquery: - a select statement inside the WHERE (or HAVING) clause of another select
statement --- 1 mark
Join: - combines columns from several tables into a single result table --- 1 mark
A subquery cannot work when the columns in the result table must come from multiple
tables not just one as is the case with join – 1 --- 3]
2. Practical
a. Write a SQL statement to create a simple table countries, which already exists,
including columns country_id, country_name and region_id set a constraint on NULL
values; (5)
[CREATE TABLE IF NOT EXISTS countries (
COUNTRY_ID varchar(2) NOT NULL,
COUNTRY_NAME varchar(40) NOT NULL,
REGION_ID decimal(10,0) NOT NULL
);]

COM222 Database Systems Page 2 of 5


b. Write a SQL statement to create a table named appliances including columns
appliance_id, and max_price and check whether the max_price amount exceeding the
upper limit 25,000. (4)
[CREATE TABLE IF NOT EXISTS jobs (

appliance_ID varchar(10) NOT NULL ,

MAX_PRICE decimal(6,0)

CHECK(MAX_PRICE<=25000)

);]

c. Given the sample table of employees below. Write an SQL statement to change the
email and commission_pct column of employees table with 'not available' and 0.10 for
all employees in department with Id number 40. (3)

[UPDATE employees SET email='not available',

commission_pct=0.10

WHERE department_id = 40;]

3. Map the the ERD below into relations. Assume that Act[a,b,c,d,e(FK)] represents mapping for an
entity/relationship “act” where a,b,..,e are its attributes, c represent primary key and (FK)
indicates attribute e is a foreign key. State any assumptions made. (15)

COM222 Database Systems Page 3 of 5


[

a) Employee(e_number, salary, last_name, first_name)

b) Contact(e_number(FK), contact)

c) Child(e_number(FK),name,dob)

d) Department(d_number,d_name,budget)

If d) then

e) Manages(d_number(FK), e_number(FK), date_started)

Else department becomes

f) Department(d_number,d_name,budget,emp_manager(FK),mgr_start_date)

If a) then

g) Course(c_number,credits,c_name,e-number(FK))

OR

h) Course(c_number,credits,c_name)

i) Teaches(e_number(FK),c_number(FK))

Else employee becomes

j) Employee(e_number, salary, last_name, first_name,c_number(FK))

k) Course(c_number,credits,c_name)

COM222 Database Systems Page 4 of 5


]

4. Consider the following information about a prescriptions chain of pharmacies


● Patients are identified by Passport number, name, address, and age
● Doctors are identified by employment number. For each doctor record the name,
specialty and years of experience
● Each pharmaceutical company is identified by name and has phone number
● For each drug, the trade name and formula must be recorded. Each drug is sold by a given
pharmaceutical company, and the trade name identifies a drug uniquely from among the
products of that company. If a pharmaceutical company is deleted, you need not keep
track of its products any longer
● Each pharmacy has a name, address and phone number
● Every patient has a primary physician. Every doctor has at least one patient.
● Each pharmacy sells several drugs and has a price for each. A drug could be sold at several
pharmacies, and the price could vary from one pharmacy to another.
● Doctors prescribe drugs for patients. A doctor could prescribe one or more drugs for
several patients, and a patient could obtain prescriptions from several doctors. Each
prescription has a date and quantity associated with it. You can assume that, if a doctor
prescribes the same drug for the same patient more than once, only the last prescription
needs to be stored
● Pharmaceutical companies have long-term contracts with pharmacies. A pharmaceutical
company can contract with several pharmacies and a pharmacy can contract with several
pharmaceutical companies. For each contract, you have to store start and end date, a text
of the contract
● Pharmacies appoint a supervisor for each contract. There must always be a supervisor for
each contract, but the contact supervisor can change over the lifetime of the contact
Draw an ER diagram that captures the preceding information. Identify any constraints not captured by
the ER diagram (15)

[ ]

COM222 Database Systems Page 5 of 5

You might also like