School of Computing and Information Technology Session: Spring 2018 University of Wollongong Lecturer: Janusz R. Getta CSCI835 Database Systems (Bridging Subject) Sample class test 23 July 2018 THE QUESTIONS 2, 3, and 4 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE DEPARTMENT ( department_name VARCHAR(30) NOT NULL, street_address VARCHAR(40) NOT NULL, postal_code VARCHAR(12) NOT NULL, city VARCHAR(30) NOT NULL, country_name VARCHAR(40) NOT NULL, manager_id DECIMAL(6) NULL, CONSTRAINT DEPARTMENT_PK PRIMARY KEY(department_name)); CREATE TABLE JOB ( min_salary DECIMAL(6) NULL, max_salary DECIMAL(6) NULL, CONSTRAINT JOB_PK PRIMARY KEY(job_title) ); CREATE TABLE EMPLOYEE ( employee_id DECIMAL(6) NOT NULL, first_name VARCHAR(20) NOT NULL, last_name VARCHAR(25) NOT NULL, email VARCHAR(25) NULL, phone_number VARCHAR(20) NULL, hire_date DATE NOT NULL, salary DECIMAL(8,2) NULL, manager_id DECIMAL(6) NULL, department_name VARCHAR(30) NULL, CONSTRAINT EMPLOYEE_PK PRIMARY KEY(employee_id), CONSTRAINT EMPLOYEE_CK1 UNIQUE(email), CONSTRAINT EMPLOYEE_CK2 UNIQUE(phone_number), CONSTRAINT EMPLOYEE_FK1 FOREIGN KEY(department_name) REFERENCES DEPARTMENT(department_name), CONSTRAINT EMPLOYEE_FK2 FOREIGN KEY(job_title) REFERENCES JOB(job_title) ); CREATE TABLE JOBHISTORY ( employee_id DECIMAL(6) NOT NULL, start_date DATE NOT NULL, end_date DATE NULL, department_name VARCHAR(30) NULL, CONSTRAINT JOBHISTORY_PK PRIMARY KEY (employee_id, start_date), CONSTRAINT JOBHISTORY_FK1 FOREIGN KEY(job_title) REFERENCES JOB(job_title), CONSTRAINT JOBHISTORY_FK2 FOREIGN KEY(employee_id) REFERENCES EMPLOYEE(employee_id), CONSTRAINT JOBHISTORY_FK3 FOREIGN KEY(department_name) REFERENCES DEPARTMENT(department_name) );
QUESTION 1 Consider a conceptual schema given below. Your task is to perform a step of logical database design, i.e. to transform a conceptual schema given above into a collection of relational schemas. For each relational schema clearly list the names of attributes, primary key, candidate keys (if any), and foreign keys (if any). Assume, that superset method must be used to implement a generalization.
QUESTION 2 Write the data definition statements of SQL that modify the structures of a database listed on a page 1 of the test paper such that: (1) It should be possible, after a modification, to add to the database information about commission percentage for each employee. The value of commission percentage is between 0 and 1. For example, 0.45 represents 45%. (2) It should be possible, after a modification, to add information that a department manager is an employee and a manager of an employee is an employee as well. (3) It should be possible, after a modification, to store information about the historical salaries of employees in a relational table JOBHISTORY. Additionally, a modification must enforce a constraint such that the end of job date must be later than the start of job date for employees in the relational table JOBHISTORY. (4) A modification must delete an attribute (a column) hire_date from a relational table EMPLOYEE. Additionally a modification must enforce a constraint such that all values of attribute salary in a relational table EMPLOYEE must be a positive.
QUESTION 3 Write the data manipulation statements of SQL that modify the contents of a database listed on page 2 of the test paper in the ways described below. Note, that you are not allowed to modify and/or to drop any consistency constraints. (1) James Bound, employee id 007, phone number 123.456.7890 has been hired on 5 March 2012 as a Stock Manager. His email is jamesbound2012@gmail.com and his salary is 8000. He works in ta department of Marketing and his manager id is 201. (2) Information about an employee number 105 must be removed from the database together with information about the employee s job history. Note, that a foreign key JOBHISTORY_FK2 does not have ON DELETE CASCADE clause. Also assume that the employee is not a manager. (3) A department Human Resources has been moved to a new location. The new address is 100 Century Avenue, Shanghai, China. Post code is 200120. (4) A department Shareholder Service has been renamed to Share Service. Update all related data in the database.
QUESTION 4 Write SELECT statements that implement the following queries. (1) Find the full names of employees who are the topmost level managers, i.e. who are not managed by any other employee. (2) List the full names of all departments and full names of employees working in each department. The results should be displayed in the descending order of department names and the full names of employees from the same department must be listed in the ascending order of the last names. (3) Find the full names of employees who work in a city Geneva in Switzerland. (4) Find the names of departments, names of countries and total number of employees for each department that hires more than 5 employees. (5) Find the employee id, first name and last name for each employee who is directly managed by Matthew Weiss. End of specification