Databases Bachelor IK December 17, 2003 Instructor: H. Afsarmanesh University of Amsterdam FINAL EXAM 1st Repetition Name: ________________________________________________ Student Number: ________________________________________________ INSTRUCTIONS: Please think carefully about each question before answering. Quality of answers is important, not quantity. It is advisable to read the entire exam before starting to answer any of the questions. Please write all your answers on the exam sheets. Put your name and student number on the exam sheet. Good Luck! Question Points Question 1 18 Question 2 22 Question 3 15 Question 4 10 Question 5 20 Question 6 15 TOTAL 100 Grade “Trade” Database description: The following description is used for two questions. Question 1 is focused on relational data modeling, while Question 2 is focused on the ER data modeling. We want to build a “Trade database” to contain information about wholesalers, retailers, products and the product-orders (for those products that retailers send orders to wholesalers). Every wholesaler accepts orders from several retailers, and every retailer sends orders to several wholesalers. Furthermore, Every wholesaler offers several products, and every product is offered by several wholesalers. Also, every retailer sends orders for several products, and every product can appear in several orders from retailers. Detailed characteristics of entities in the database: Every seller in the market, being a retailer or wholesaler, has a unique identifier number in the database, plus its address and phone number. Each product has a unique merchandise number in the database, plus its color, weight, and size. Each order has a unique order number in the database, plus its date and status. 2 Question 1. (18 points) a. Draw the ER diagram for the Trade database, indicating all the schema elements. In this diagram, you can introduce names for some schema elements, when and if necessary. b. List all the entity sets. c. List all the relationship sets. d. List all sub-classes. e. List all super-classes. 3 Question 2. (18 points) a. Sketch a good relational schema for the Trade database to capture all the information given to you above. This schema must define the information as simple as possible with minimal logical redundancy. b. In every relation you defined above, “circle” its primary key in the relation. c. For every relation list its foreign keys below. d. Define all functional dependencies that hold in this schema. e. For every relation, specify if it is in 3rd normal form or not. 4 Question 3. (15 points) This question has 3 sections focused on the DMLs for relational databases: a. Specify for each of the following Data Manipulation Languages (DMLs) if the “duplicate tuples” are by default “kept” or “removed”. Relational algebra SQL QBE b. Specify the operation/command in the following DMLs, that when used it reverses this default/automatic treatment of duplicate tuples. c. Relational algebra SQL QBE In the following example relation: CUSTOMER = (CUSTOMER-ID, ACCOUNT-NUMBER, BALANCE) Give an example “question” (in English) for this relation that if the DML used for writing this query keeps the duplicate tuples, the results may be wrong. 5 The following “employee” database is used for the next 3 questions. Question 4 focuses on the SQL schema creation and data modification commands. Question 5 focuses on SQL queries / data retrieval. Question 6 focuses on the QBE queries. Consider the following relational schema for the employee database. The primary key is underlined in each relation. EMPLOYEE (EMPLOYEE-NAME, STREET, CITY) WORKS (EMPLOYEE-NAME, COMPANY-NAME, SALARY) COMPANY (COMPANY-NAME, CITY) MANAGES (EMPLOYEE-NAME, MANAGER-NAME) Question 4. (10 points) a. Give the SQL schema definition for this employee database. Choose and specify an appropriate domain for each attribute in each of the relations. 6 EMPLOYEE (EMPLOYEE-NAME, STREET, CITY) WORKS (EMPLOYEE-NAME, COMPANY-NAME, SALARY) COMPANY (COMPANY-NAME, CITY) MANAGES (EMPLOYEE-NAME, MANAGER-NAME) b. Write the SQL data modification command for: Modifying the database so that Jones now lives in the Newtown city. c. Write the SQL data modification command for: Giving all the employees of the Commerce Bank a 10 percent raise. Question 5 (20 points) Construct the following SQL queries for this employee relational database. a. Find the names of all employees work for the First Bank Corporation. 7 b. Find the names, street address, and cities of employees who work for the First Bank. Corporation, and earn more than $10,000. c. Find all the employees in the database who live in the same cities and on the same streets as do their managers. d. Find all employees who earn more than the average salary of all employees of their company. 8 EMPLOYEE (EMPLOYEE-NAME, STREET, CITY) WORKS (EMPLOYEE-NAME, COMPANY-NAME, SALARY) COMPANY (COMPANY-NAME, CITY) MANAGES (EMPLOYEE-NAME, MANAGER-NAME) Question 6. (15 points) Construct the following QBE queries for the employee relational database. a. Find the names, street address, and cities of employees who work for the First Bank Corporation, and earn more than $10,000. b. Find all the employees in the database who live in the same cities and on the same streets as do their managers. c. Find all employees who live in the city where the company for which they work is located. 9