You are on page 1of 5

CIS331 Database Programming

Spring 2014 Midterm Exam


Name:

4 points for each multiple choice question. 7 points for Q18. 5 points for each other SQL question.
1 2 3 4 5 6 7 8 9 10

11

12

13

14

15

16

17

CIS 331 Spring 2014 Midterm Exam


1. The MANAGER_ID attribute in L_EMPLOYEES relational table is: (a) Foreign key to L_EMPLOYEES relational table. (b) Primary key to L_DEPARTMENTS relational table. ( c ) Foreign key to L_DEPARTMENTS relational table. (d) Primary key to L_EMPLOYEES relational table. 2. Some foods have no price increase dened. CEO wants to reset it to 0. (a) UPDATE l_foods SET price_increase = 0 WHERE price_increase = NULL; (b) UPDATE l_foods SET price_increase = 0 WHERE price_increase IS NULL; ( c ) UPDATE l_foods SET price_increase = 0 WHERE price_increase = (d) UPDATE l_foods SET price_increase = 0 WHERE price_increase < 0.05; 3. Which description about l_employees table is true? (a) Employee without rst name is acceptable. (b) Employee without dept_code is acceptable. ( c ) Employees with same rst name and last name are acceptable. (d) Employees sharing phone number are acceptable. 4. Which of the following about views is true? (a) View is also called virtual table. (b) You can create view from other views. Therefore, view is not required to have a base table. ( c ) View stores data. It takes disk space. (d) It takes time to update view when the base table is updated. 5. The CEO wants a list of foods except those supplied by ARR, ASP, and CBC. (a) SELECT description FROM l_foods WHERE NOT (supplier_id=ARR OR supplier_id=ASP OR supplier_id=CBC) (b) SELECT description FROM l_foods WHERE NOT supplier_id IN (ASP, ARR, CBC) ( c ) All the other answers (d) SELECT description FROM l_foods WHERE supplier_id NOT IN (ASP, CBC, ARR) 6. What type language is the UPDATE statement? (a) View Denition Language (VDL) (b) Data Manipulation Language (DML) ( c ) Data Denition Language (DDL) (d) STORAGE Denition Language (SDL)

Version n. 2 Page 1

7. Which description about the SQL below is correct? SELECT supplier_id, price, description FROM l_foods ORDER BY 1, 2 (a) It shows error message. (b) The output will be in ascending order for price between 1 and 2. ( c ) The output will be in ascending order of supplier_id and price. (d) The output will be in ascending order for numeric attribute (price) . 8. How do you know the schema of L_FOODS table? (a) SCHEMA l_foods; (b) DESC l_foods; ( c ) After you created the table, there is no way to know the schema. (d) SELECT SCHEMA (l_foods) FROM dual; 9. The PRODUCT_CODE attribute in L_PRODUCTS relational table is: (a) Foreign key to L_FOODS relational table. (b) Primary key to L_LUNCH_ITEMS relational table. ( c ) Primary key to L_PRODUCTS relational table. (d) Foreign key to L_LUNCH_ITEMS relational table. 10. Which of the following is Data Denition Language (DDL) command? (a) DELETE (b) INSERT ( c ) SELECT (d) CREATE TABLE 11. The CEO wants a list of supplier name and food description. Which SQL statement will do the work? (a) SELECT f.product_code, p.description FROM l_products p, l_foods f ON p.product_code=f.product_code; (b) SELECT f.product_code, p.description FROM l_products p, l_foods f WHERE p.product_code=f.product_code; ( c ) SELECT f.product_code, p.description FROM l_products p, l_foods f; (d) SELECT f.product_code, p.description FROM l_products p JOIN l_foods f WHERE p.product_code=f.product_code; 12. Which input of NULL will be denied? (a) Input to Foreign key eld. (b) All the other answers. ( c ) Input to Primary key eld. (d) Input to unique constraint attribute when a NULL already existed. ( e ) Input to unique constraint attribute when 0 (zero) is existed.

Version n. 2 Page 2

13. Which description about the following SQL statements is correct? (1) SELECT * FROM l_employees e LEFT JOIN l_departments d ON e.dept_code = d.dept_code (2) SELECT * FROM l_employees e RIGHT JOIN l_departments d ON d.dept_code = e.dept_code (3) SELECT * FROM l_departments d RIGHT JOIN l_employees e ON d.dept_code = e.dept_code (4) SELECT * FROM l_employees e FULL JOIN l_departments d ON e.dept_code = d.dept_code (a) When you have more data, all four Statements will show dierent results. (b) Statement (1) and Statement (3) show same results. ( c ) Statement (1) and Statement (2) show same results. (d) Statement (2) and Statement (3) show same results. 14. The CEO wants a list of suppliers names and food description they supplied, including suppliers without supplying any food. Which SQL statement will do the work? (a) SELECT supplier_name, description FROM l_suppliers s JOIN l_foods f ON s.supplier_id=f.supplier_id; (b) SELECT supplier_name, description FROM l_suppliers s LEFT OUTER JOIN l_foods f ON s.supplier_id=f.supplier_id; ( c ) SELECT supplier_name, description FROM l_suppliers s RIGHT OUTER JOIN l_foods f ON s.supplier_id=f.supplier_id; (d) SELECT supplier_name, description FROM l_suppliers s, l_foods f WHERE s.supplier_id=f.supplier_id; 15. There are INSERT statements to add data into L_FOODS. Lets focus only on values of (Supplier_ID, Product_Code, Price, Price_Increase). Which of the following is correct to insert into L_FOODS? Hint: Check constraints. (a) ( JPS, NULL, 6.5, .8); (b) ( FSN, GS, 12.0, 1.0); ( c ) ( ARR, AS, 3.6, NULL); (d) ( NULL, SW, 5.5, .5); 16. The CEO decided to increase credit limit by 5 for those work for SHP and MKT. Which SQL statement will the CEO need? (a) UPDATE l_employees SET credit_limit=credit_limit + 5 WHERE dept_code BETWEEN MKT AND SHP; (b) UPDATE l_employees SET credit_limit=credit_limit + 5 WHERE dept_code=SHP OR dept_code=MKT; ( c ) UPDATE l_employees SET credit_limit=credit_limit + 5 WHERE dept_code=SHP AND dept_code=MKT; (d) UPDATE l_employees credit_limit=credit_limit + 5 WHERE dept_code=SHP AND MKT ; 17. You are new to a database position. Your supervisor shows you the SQL below and asks you to point out which one, E or W, is a view. select E.EID, W.PNO from E join W on E.EID=W.EID (a) Dont know. You cant tell by looking at this SQL alone. (b) W. View must not be listed before table. ( c ) Neither. View name must be endded with _V. (d) Neither. View cant be used in join.

Version n. 2 Page 3

SQL programming questions Use your regular user account from homework 1 for the following questions.
Book_No 201403001 Title SQL Samples Publish_Date Mar-01-2014 Price 11.99 ePrice 10.99 Data_Entry YourName

18. Create a table for schema and data shown above. Below are additional requirements. Table name: Book_YourThreeDigit_ID Book_No: primary key Title, publish date, and price attributes are not allowed to be empty. eBook price (ePrice) shall be cheaper than regular price. 19. Insert the sample record. Use sysdate for Publish_Date. Use your own name in Data_Entry. 20. eBook price should be 20% off from traditional price. Update the ePrice for all books. 21. Show all book details. Format publish date to display date and time in format like, 02/28/2014 11:05:03 AM. 22. Delete book with title Sql Samples. Ignore the case in spelling. Show details of all books. 23. Delete the table. 24. Use HR. Show department name and its managers name.