BSc (Hons) Computer Science with Network Security Cohort: BCNS/14/FT Examinations for 2014-2015 / Semester1 MODULE: DATABASE DESIGN MODULE CODE: DBT 1111C Duration: 2 Hours 30 Mins Instructions to Candidates: 1. Answer ANY FOUR questions. 2. Questions may be answered in any order but your answers must show the question number clearly. 3. Always start a new question on a fresh page. 4. All questions carry equal marks. 5. Total marks 100. 6. Appendix included [3 pages] This Exam Paper contains 5 questions and 11 pages. Page 1 of 11
ANSWER ANY FOUR QUESTIONS QUESTION 1: (25 MARKS) (a) Explain the term query and list any four functions performed by a query. [1 + 4 marks] (b) List and briefly describe five potential benefits of the database approach compared to conventional file systems. [5 X 2 marks] (c) Differentiate between Database System and Database Management System. Support your answer with an appropriate example of each.. [4 marks] (d) Explain the terms entity integrity and referential integrity and state how they should be supported in relational database management systems. Support your answer with appropriate example [6 marks] QUESTION 2: (25 MARKS) The UTM Flower and Plant Nursery (UFPN) has been created by the UTM Student Union in order to help generate some additional funds to finance some of their activities. The UFPN sells seeds and plants of flowers and vegetables to the public in general as well as insecticides/pesticides and fertilizers (both chemical fertilizers and manure). All these items are recorded under one generic Page 2 of 11
component i.e. Product but with their respective details as specific items. Usually the nursery produces all of its seeds/plants but in periods of high demand additional seeds/plants are bought from local planters. The UFPN wishes to computerize its database system to better monitor its transaction and stock. The customers can be any of these: Public, Staff, or Student (Including Student Union members). The system would hold data about the following: CUSTOMER: Customer Number (C_NO), Forename (CFName), Lastname (CLName), Street, City, Phone1 (Home), Phone2 (Mobile), Email, National ID Number (NIC), Credit Card Number (CCN), Type (Public, Staff, Student). For the public, the following details are also recorded: Employed/Unemployed/Self Employed and Employer address. For UTM staff, Staff Number (S_NO), Department (Dept) and School are recorded. For the student, Student Number (St_NO), Cohort and Programme as well as whether they are Student Union member or not, are recorded. All these details will be later used to generate statistics about the sales and revenues. At the end of each academic year, during the End of Year Party, student who sells/buy more products are rewarded with a symbolic shield. Only Student Union members are allowed to operate as staff for the nursery. They will buy additional seeds/plants from local planters, Fertilizers and Herbicides/pesticides from local suppliers. Details recorded for planters are: Planter_Id (P_Id), Planter forename (PFName), Planter last name (PLName), Planter Category (Fruits/Vegetables) Address, City, Phone1, Phone2, Fax, and Email. Details recorded for suppliers are: Supplier_Id (S_Id), Supplier forename (SPFName), Supplier last name (SPLName), Supplier Type (Fertizers/Herbicides/Pesticides) Address, City, Phone1, Phone2, Fax, and Email. Page 3 of 11
Details of payment include Payment_Id (PY_Id), Payment date (PY_Date), Amount Tendered (Amt_T), Amount Returned (Amt_R), Method (Cash (CH) or Credit Card (CC). Details of Stock are Stock date (STK_date), products Name and their quantity. Products fall under the following categories: Seed: Seed Id (SD_Id), Common Name (CN), Scientific Name (SN), Seed Type (Fruits/Vegetables), Quantity in grammes (Qty), Production date (Prod_date), Expiry date (Exp_date). Plant: Plant Id (PL_Id), Common Name (CN), Scientific Name (SN), Plant Type (Fruits/Vegetables), Quantity in grammes (Qty), Production date (Prod_date), Expiry date (Exp_date). Fertilizer: Fertilizer Id (F_Id), Common Name (CN), Scientific Name (SN), fertilizer Type (Chemical/Organic), Quantity in Kilogrammes (Qty), Production date (Prod_date). Medecine: Medecine Id (M_Id), Common Name (CN), Scientific Name (SN), Medecine Type (Herbicide/Pesticides), Quantity in Litres (Qty), Production date (Prod_date), Expiry date (Exp_date). Apart from the Ids for the different categories, a Product Id (PR_Id) and a product Name (PR_Name) are also recorded in the system. A customer can buy any number of products and a product may be bought by one or more customers, depending on its availability in stock. A planter may provide any number of seeds/plants and a seed/ plant is provided by one or more planter. A fertilizer is supplied by one or more supplier. Each supplier supplies one or more fertilizers. An Herbicide/Pesticide is supplied by one or more suppliers. Each supplier can supply one or more herbicide/pesticide. A student Union member can sell one or more product. A product can be sold by one or more student union member. Page 4 of 11
A student Union member can buy one or more product. A product can be bought by one or more student union member. After each transaction, payment is effected either by cash or credit card and the stock is updated immediately. (a) Produce an Entity Relationship Diagram (Logical Data Structure) for the above scenario. For each entity list the attributes and underline their respective primary key. Identify any double relationship that may exist between any two entities. [11 Marks] (b) Translate your ERD into a relational database schema. [10 Marks] (c) Identify two Supertype entities and their respective Subtypes entities in the system. [2+2 Marks] QUESTION 3: (25 MARKS) (a) Explain the need for Normalization in Database Design and define the following terms with appropriate example: (i) First Normal Form (ii) Second Normal Form (iii) Third Normal Form. [8 marks] Based on the data provided below (Fig 3) carry out the tasks mentioned below (i.e. parts (i) to (iv)) to normalize the table up to the third Normal Form Page 5 of 11
S_ID is student ID and S_Name is student name Br_NO is Branch number and B_Name is Branch name C_ID is Course ID Ins_ID is Instructor ID and Ins_Name is Instructor Name Assumptions: Each student is enrolled on at least one course Each course has got its minimum break through to be run Each branch is running at least one course. Fig 3 (b) Explain why the table is un-normalised and convert it into 1 st Normal Form identifying an appropriate Primary key for this 1NF table. [2 + 3 marks] (c) Draw the 1 st Normal Form Table. [4 marks] (d) Decompose the 1 st NF into 2 nd Normal Form [4 marks] (e) Decompose the 2 nd Normal Form into 3 rd Normal Form [4 marks] Page 6 of 11
QUESTION 4: (25 MARKS) Using the tables provided in the Appendix A, express the following queries in SQL USING ORACLE 9I SYNTAX. (a) Write the SQL code that will create the table structure for the (i) OWNER table (without specifying any primary key). (ii) PET table (without specifying C_NO and V_NO) [3 + 3 marks] (b) Having created the table OWNER in question (a) above, write the SQL code that will enter the first data row into the Experiment table. [3 marks] (c) Add a PRIMARY KEY constraint to make O_NO the primary key of the CUSTOMER table [2 marks] (d) Add a FOREIGN KEY constraint to make O_NO the foreign key in the PET table. [3 marks] (e) Add a new column in the OWNER table with the following data definition (Column Name EMAIL of Varchar2 data type and field size of 25, and contains a constraint that data cannot be NULL ) [2 marks] (f) The parrot named Angel suffered from a rare disease and passed away recently. Write the SQL code to delete the parrot from the PET table. [2 marks] (g) The Veterinary Issacjee recently left the country to work abroad for two years. During his absence from the country he has requested Dr Huang to continue his consultation with his patient. Consequently you have been asked to update the PET table. Write SQL code to update the veterinary number (V_N0) [3 marks] Page 7 of 11
(h) Write SQL code to display the name of the youngest dog registered in the system. [4 marks] QUESTION 5: (25 MARKS) This question refers to the database tables given in the Appendix A. Formulate each of the following queries in Relational Algebra. (a) Display the last names of all owners who own both a dog and a cat. [6 marks] (b) Display the forename of all owners who own either a dog or a cat. [6 marks] (c) Display the last names of all owners who do not own a cat. [6 marks] (d) Display the forenames and last names of all owners who own all categories of pet at their place. [7 marks] Page 8 of 11
APPENDIX A Data in Appendix A are meant for Question 4 and Question 5. Below are three tables: OWNER, PET AND VETERINARY. The OWNER Table consists of the OWNER Number (O_No) as Primary key, Fname as owner Forename, Lname as Owner Lastname, Street, City and Phone. The PET Table consists of the Pet Number (P_NO) as Primary Key, Pet name as P_name, Age (in Months), Category, vaccinated (YES/NO), O_NO, V_NO. The VETERINARY Table consists of the Veterinary Number (V_NO) as Primary key, Veterinary First Name (Vfname), Veterinary Last Name (Vlname), Address, City and Mobile number. A customer can have one or more pet(s). A pet is bought by one customer only. A veterinary can consult one or more pets of different category. A pet is consulted by one veterinary. Your task is to express each of the given queries in SQL using Oracle 9i syntax. Example data are provided in these tables for your convenience but note that they are only example data. Your queries must work for all potential data residing in the given tables, not just those illustrated here. Page 9 of 11
APPENDIX A FOR QUESTION 4 AND QUESTION 5 Page 10 of 11
***END OF PAPER*** Page 11 of 11