MIS 3353 Quiz 2 Nov. 21, 2002 Name __________________________________________ Part I Multiple Choice (30 pt) Mark all correct answers. Explain any answers that you need to. 1 A relational database connects tables with a) Pointers b) Indexes c) Keys and Foreign Keys d) Hashed connections 2 In a SQL SELECT statement the phrase GROUP BY Name, Major HAVING City = ‘Norman” a) Generates an error b) Produces only groups from Norman c) Produces a table with one record for each student and major d) Produces only one record for Norman 3 In a SQL SELECT statement the phrase FROM (SELECT Name FROM STUDENT) S, STUDENT a) Generates an error b) Renames the student table and calls it S c) Creates a new (virtual) table with nothing but student names in it and calls it S d) Creates a table called FROM 4 You have the table STUDENT (ID, Name, Major). Students may have more than one major. To list all students who are NOT MIS majors you should include which statement in your SQL query a) SELECT * FROM STUDENT WHERE Major <> ‘MIS’ b) SELECT * FROM STUDENT GROUP BY Major HAVING Major <> ‘MIS” c) SELECT * FROM STUDENT WHERE ID NOT IN (SELECT * FROM STUDENT HAVING Major = ‘MIS’) d) SELECT * FROM STUDENT WHERE ID NOT IN (SELECT ID FROM STUDENT WHERE Major = ‘MIS’) 5 A 3nf violation means a) An attribute in the table can have several values in one record b) An attribute in the table depends on only one part of a concatenated key c) An attribute in the table belongs in another entity d) The table has no primary key 6 Normalization a) Identifies incorrect referential integrity b) Identifies incorrect placement of attributes c) Identifies incorrect cardinality d) Identifies incorrect foreign keys 7 Normalized databases a) Are designed for efficient update b) Are designed for efficient retrieval c) Remove data redundancy d) Remove key/foreign key redundancy 8 An index a) Makes retrievals faster b) Increases the space needed for the database c) Makes updates faster d) Is always generated for a primary key 9 A pointer in a data structure a) Contains a primary key value b) Contains an attribute value c) Contains a foreign key value d) Contains a physical location INSTRUCTOR CLASS 10 The data model above represents a 1:M relationship between instructor and classes taught. You wish to speed up the process of looking up INSTRUCTOR.Name whenever you look up class. You can a) Put Class Name in the INSTRUCTOR table b) Put Instructor Name in the CLASS table c) Index the Name attribute in the INSTRUCTOR table d) Index the Name attribute in the CLASS table Part II: Completion (40 pt.) 1. STUDENT (Student#, StudentName, StudentPhone, TitleOfClassTaken) Circle the lowest normalization error: 0nf, 1nf, 2nf, 3nf, no error. Describe the error: TitleOfClassTaken is multi-valued Correct the error: STUDENT( Student#, StudentName, StudentPhone) CLASS( Class#, TitleOfClass) STUDENT-CLASS( Student# , Class# ) 2. ORDER(Order#, Date, Customer, CustomerAddress) Circle the lowest normalization error: 0nf, 1nf, 2nf, 3nf, no error. Describe the error: Customer and CustomerAddress belong to another table Correct the error: ORDER( Order# , Date, Customer# ) CUSTOMER( Customer# , Customer, CustomerAddress) 3. STUDENT (150) Query Use the data model below to calculate the number of records accessed in each of the tables. Given an instructors name, find all of the students enrolled in her/his classes. SECTION (30) STUDENT-SECTION (600) Table: INSTRUCTOR SECTION Size: Attribute Index? 15 Name N 7.5 INSTRUCTOR (15) STUDENT 30 Instr# N STUDENTSECTION 600 Sec# Y 1*30 1*2*20 1*2*20*1 150 Stu# Y 4. The OU Auto Repair Shop wants an information system to track its operations It tracks vehicle make, model, year and vehicle identification number (VIN) for each vehicle it repairs. Each time a customer brings a vehicle in the system creates a repair order that captures date, vehicle make, model, color, and vehicle identification number (VIN) for the vehicle. Different customers may bring the same vehicle in for repair at different times. Only one customer is listed on any repair order, however. The system keeps customer name, contact phone, and address for individuals listed on the repair order. Businesses may bring in vehicles, and in that case the system needs customer name (person who brought in the vehicle) business name, contact phone, and business account number. The repair order lists repair codes, description and standard number of hours for each repair task requested. The repair information comes from the Chilton standard repair table that lists codes and standard times for most repairs. Each order can include several different repair requests. The same repair (for example, replace a tire) may occur several times on a single order. The system must track employee ID, name and location for the employee that does each repair task. The system must also track parts used. Each part can contain other parts. A part may be contained in several other parts. The system tracks ID, description and price for each part in inventory. Draw an E-R diagram for this situation. Include keys, foreign keys, cardinality and referential integrity indicators. BUSINESSCUSTOMER CUSTOMER Cust# (PK) Cust# (PK) BusinessName Address Account d VEHICLE VIN (PK) Make Model Year ORDER Ord# (PK) VIN (FK) Cust# (FK) Date PARTORDERED Ord# (PK) ID# (PK) Quantity REPAIRORDERED Num (PK) Code# (FK) Ord# (FK) Emp# (FK) REPAIR Code# (PK) Description Time CUSTOMER Cust# (PK) Name ContactPhone EMPLOYEE Emp# (PK) Name Location PART ID# (PK) Description Price PART-CONTAINS ID# (PK) ContainsID# (PK) Part II: SQL (30pt) Course 3013 3013 3013 3033 3033 3033 3033 3353 3353 3353 3363 3363 3363 3373 3373 3373 4663 4663 4663 4663 Sec 001 002 004 002 003 901 902 001 002 901 001 002 003 002 003 004 900 902 903 904 Title C Programming C Programming C Programming Visual Basic Visual Basic JAVA JAVA Databases Databases Databases Infrastructure Infrastructure Infrastructure Systems Theory Systems Theory Systems Theory Systems Project Systems Project Systems Project Systems Project SCHEDULE Hours Days 8:30 AM M,W,F 1:30 PM T,R 3:00 PM T,R 3:00 PM T,R 3:00 PM M,W 6:30 PM W 4:30 PM M,W 10:30 AM T,R 12:00 PM T,R 4:30 PM T,R 1:30 PM M,W 1:30 PM T,R 3:00 PM M,W 9:00 AM T,R 1:30 PM M,W 3:00 PM M,W 6:30 PM M 6:30 PM M 4:30 PM M 4:30 PM M Instructor Ferguson Warner Warner Ratwatte Ratwatte Kemp Ratwatte Carte Carte Carte Carter Croes Warner Miranda Shaft Shaft Kemp Schwarzkopf Price Ferguson Room AH 100 AH 101 AH 101 AH 100 AH 100 AH 101 AH 100 AH 311 AH 311 AH 315 AH 101 AH 104 AH 104 AH 101 AH 112 AH 112 AH 150 AH 150 AH 255 AH 150 Max Enrolled 35 25 35 23 35 30 35 35 35 30 25 15 35 30 30 30 30 30 30 25 30 30 30 24 30 25 30 25 30 28 30 20 24 24 24 18 18 18 18 18 PREREQUISITE Course PreCourse 3033 3013 3033 3353 3353 2113 3353 3013 3363 3353 3373 3353 4663 3033 4663 3353 4663 3363 4663 3373 Assume you have the tables above. Write SQL to execute the following queries. 1. List Course, Title, Number-of-sections, Number-of-students-enrolled for all courses that meet on Mondays and have at least 3 sections offered. SELECT Course, Title, Count(*), Sum(Enrolled) FROM Schedule WHERE Days LIKE ‘*M*’ GROUP BY Course, Title HAVING Count(*) >=3; 2. List Instructor and Number-of-students-enrolled for all instructors who do NOT teach on Mondays. SELECT Instructor, Sum(Enrolled) FROM Schedule WHERE Instructor NOT IN (SELECT Instructor FROM Schedule WHERE Days LIKE ‘*M*’) GROUP BY Instructor 3. List each Instructor, Course, Number-of-students-enrolled for all of that instructors sections of the course, and Number-of-students-enrolled for all sections of that course. SELECT Instructor, Course, Sum(Enrolled), T.Total FROM Schedule, (SELECT Course, Sum(Enrolled) AS Total FROM Schedule GROUP BY Course) T WHERE Schedule.Course = T.Course GROUP BY Instructor, Course, T.Total 4. List each Instructor, Total-Number-of-Students-Enrolled in all classes for the instructor, and the Total-Number-of-Students-Enrolled in all classes together. SELECT Instructor, Sum(Enrolled), T.Total FROM Schedule, (SELECT Sum(Enrolled) AS Total FROM Schedule) T GROUP BY Instructor, T.Total 5. List each Title and Prerequisite-Title for all courses that have prerequisites. SELECT C.Title, Pre.Title FROM Schedule C, Schedule Pre, Prerequisite WHERE C.Course = Prerequisite.Course AND Prerequisite.PreCourse = Pre.Course