Section A Fig. 1: Retail Store Database: For books purchased by clients BOOKS Bookcode Title Author Numpages B1 Database Theory Halevy 800 B2 Database Systems Elmasri 1240 B3 Java Dietel 1000 B4 Data Mining Han 1400 B5 C Programming Ezeife 640 Cname Address 123 Smith Sunset Ave., Windsor 124 Balam Tecumseh Rd., Windsor 125 Anna WyandoQe Str., Windsor CLIENTS ClienLd PURCHASE ClienLd Bookcode 123 B1 123 B4 123 B5 124 B5 125 B1 125 B2 125 B5 Use the RETAIL STORE database of Fig 1 to answer the next few questions. 1. The result of the relational algebra query: πClientid, Bookcode (Purchase) -:- πBookcode (σNumpages <= 800(Books)) is __. Note that the symbol -:- means division. 1 A. Clientid Bookcode 123 B1 124 B5 125 B1 125 B5 B. Clientid Bookcode 125 B1 125 B5 C. Clientid 123 125 D. Clientid 125 E. None of the above 2. The result of the following relational calculus query on the Retail store database is: {w.Clientid | Purchase(w) and ((∀b) ((NOT(Books(b)) OR (w.Bookcode = b.Bookcode and b.Numpages <= 800)))} A. Clientid Bookcode 123 B1 124 B5 125 B1 125 B5 B. Clientid 125 C. Clientid Bookcode 125 B1 125 B5 D. Clientid 124 125 2 E. None of the above 3. The SQL query to retrieve the number of books Purchased by client ‘Anna’ is ____. A. SELECT w.clientid, count(w.Bookcode) from Purchase w, clients c where w.clientid=c.clientid and c.Cname= ‘Anna’ group by w.clientid; B. SELECT count(w.Bookcode) from Purchase w group by w.clientid; C. SELECT w.clientid, count(b.numpages) from Purchase w, books b where w.bookcode=b.bookcode and Cname = ‘Anna’ group by w.clientid; D. All of the above E. None of the above 4. In SQL, to get the names of clients who Purchased books B1 and B2, use? A. SELECT Cname FROM Clients where Bookcode = B1 and Bookcode = B2; B. SELECT Cname FROM Clients c, Purchase w where Bookcode = B1 and Bookcode = B2; C. SELECT Cname FROM Purchase where Bookcode = B1 AND Bookcode = B2; D. All of the above E. None of the above 5. The SQL query for retrieving and presenting unique (not duplicates) client names and their addresses with only the address sorted in descending order is _____. A. SELECT distinct(Cname), Address FROM Clients ORDER BY Address; B. SELECT Cname, Address FROM Clients ORDER BY Address desc; C. SELECT distinct(Cname), Address FROM Clients ORDER BY Address desc; D. SELECT distinct(Cname), Address FROM Clients ORDER BY Address asc; E. None of the above Fig. 1: RETAIL STORE Database: For books Purchased by Retail store clients (Represented) BOOKS Bookcode Title Author Numpages B1 Database Theory Halevy 800 B2 Database Systems Elmasri 1240 B3 Java Dietel 1000 B4 Data Mining Han 1400 B5 C Programming Ezeife 640 CLIENTS 3 ClienLd Cname Address 123 Smith Sunset Ave., Windsor 124 Balam Tecumseh Rd., Windsor 125 Anna WyandoQe Str., Windsor PURCHASE ClienLd Bookcode 123 B1 123 B4 123 B5 124 B5 125 B1 125 B2 125 B5 6. With SQL, how can you delete the records where the Title is "Database Theory" from the BOOKS Table? A. DELETE ROW Title = 'Database Theory' FROM BOOKS; B. DELETE Title = ‘Database Theory' FROM BOOKS; C. REMOVE Title = ‘Database Theory' FROM BOOKS; D. DELETE FROM BOOKS WHERE Title = ‘Database Theory'; E. None of the above 7. Which of the following indicates the processing order for the indicated clauses in SQL? A. WHERE, HAVING, GROUP BY B. WHERE, GROUP BY, HAVING C. GROUP BY, HAVING, WHERE D. HAVING, WHERE, GROUP BY E. None of the above 8. From Fig. 1, the result of the relational algebra query πTitle (σCname=`Smith’ ( Books Purchase Clients )) is: (Note that comma marks another row of result and the hour glass symbol as used above represents natural join). A. Database Theory, Java B. Database Theory, Data Mining, C Programming C. C Programming 4 D. Database Systems E. None of the above 9. The result of the following relational calculus query on Fig. 1 database is: {b.Bookcode, b.Author | Books(b) and b.Numpages > 800} A B2 . B4 B . B4 B2 Han B3 B4 Dietel Han C . Elmasri B2 Elmasri D B3 Dietel . E. None of the above 10. The following relational algebra query (Books Purchase) representing natural join is equivalent to ___________. A. Books U Purchase. B. Books x Purchase. C. σ Books.Bookcode=Purchase.Bookcode (Books x Purchase). D. Books ∩ Purchase E. None of the above 11. . Which of the following relational algebra operators require that its operands be type compatible? A. Cartesian product B. Set difference C. Natural join 5 D. All of the above E. None of the above 12. A secondary index ______: A. B. C. D. E. Has its index field the same as the ordered key field in the primary data file. Is the same as a primary index. Has to be a single level index. All of the above None of the above 13. Some of the differences between the B-tree and B+tree index structures are: A. One is a static and the other is a dynamic structure. B. One can retrieve data in O(bi) while the other in O(logfanout bi) for block bi. C. One is a single level index and the other is a multilevel index. D. All of the above E. None of the above 14. The Retail store database of Fig. 1 is not in 3NF. A. FALSE. B. TRUE. C. MAY BE. D. All of the above E. None of the above 15. The Retail store database of Fig. 1 is in BCNF. A. B. C. D. E. FALSE. TRUE. MAY BE. All of the above None of the above 6 Section B (70 marks ): This section has 4 questions: Fig. 2: The ER model Diagram for the Vaccination Database Name SSN Cname jobtype age M PERSON Cntid VACCINATES city budget N CENTRE dose N M ADMINISTERS time managerid date M Vname VACCINE formula madeby 1 price SELLS cname cphone 1 PCOMPANY Consider the ER diagram of Fig 2 which shows a schema for a Database containing information about vaccination. Answer question 1 using this figure. 7 Question 1: (total marks: 20 for 10 + 6 + 4) a. Define a relational database schema representation for this database system ER model, clearly defining all tables schemas for entities and relationships, with their attributes, identifying their primary keys and foreign key attributes constraints in the schemas. (10 marks) b. Write all the SQL instructions to create all 7 database tables with all their constraints specified. (6 marks) c. Write an SQL query for the English query “Print the vaccine name, its manufacturing pharmaceutical company name and phone number, and the selling price of each vaccine”. (4 marks) Solution for Question 1 (20 marks for all of a to c) Sub questions Answers a. RelaLon DB for Fig 2. (10 marks) Define a relational database schema representation for this database system ER model, clearly defining all tables schemas for entities and relationships, with their attributes, identifying their primary keys and foreign key attributes constraints in the schemas. That is: For Entities and attributes (5 marks) in ER And Relationships and attributes (5 marks) in ER 8 b. creaLng the 7 tables with SQL instrucLons (6 marks) c. SQL query 4) marks) b. creaLng the 7 tables with SQL instrucLons c. Write an SQL query for the English query “Print the vaccine name, its manufacturing pharmaceuLcal company name and phone number, and the selling price of each vaccine. 9 Question 2: (total marks = 20 for 5 + 5 + 5 + 5) a. Consider the universal relation R = {A, B, C, D, E, F, G} and the set of functional dependencies (FDs) in this database is: FD1: {A, B} -> {C, D, E, F, G}, FD2: {E} -> {F, G}. FD3: {B} -> {D} Given that the key for R is {A, B}, i) Is the relation R in 3NF? Explain your answer using all possible functional dependencies. (5 marks) ii) Decompose R into 3NF relations specifying the primary keys and functional dependencies that exist in each of the relations and thus, in the database. (5 marks) b. Given the PLAYER record relation schema: PLAYER (Playerid, Gameid, Playername, GameScore) Note that in (a), you were given the FDs. In question (b), it is your job to identify the FDs that may hold in this database from the description, meaning of data attributes, and their constraints. Assume that a player may play multiple games (just as a student can take multiple courses) and that score (e.g., 70%) achieved for each game is entered. The primary key is (Playerid, Gameid). Other dependencies may exist from the meaning of this domain which you should understand as a database designer and you can enter any assumptions you make. It is your job to find all functional dependencies that may exist in this database so you can use this information to decide whether the database is normalized or not as asked in the following questions. i). Is this relation in 3NF? Discuss using functional dependencies whether or not the relation PLAYER is in 3NF. (5 marks) ii) Normalize the relation PLAYER into 3NF set of relations if not in 3NF, showing your new normalized database with its functional dependencies. (5 marks) Que 2 (20 marks for all of a to d) 10 (a) (i) Is R in 3NF ? Discuss with funcLonal dependencies. (5 marks) (a)(ii) Decompose R into 3NF if not in 3NF. Show FDs of new database. (5 marks) (b)(i) Is PLAYER in 3NF? Discuss with funcLonal dependencies. (5 marks) 11 (b)(ii) Normalize PLAYER into 3NF if not already in 3NF. Show FDs of new database. (5 marks) 12 Fig. 3: RETAIL STORE Database: Another version of books Purchased in Retail store clients BOOKS Bookcode Title Author Numpages B1 Database Theory Halevy 800 B2 Database Systems Elmasri 1240 B3 Java Dietel 1000 B4 Data Mining Han 1400 B5 C Programming Ezeife 640 Cname Address 123 Smith Sunset Ave., Windsor 124 Balam Tecumseh Rd., Windsor 125 Anna WyandoQe Str., Windsor CLIENTS ClienLd Publisher PNAME PPHONE 1(732) 524-0400 1 (877) 633-2001 1 (888) 463-6332 1 (800) 265-7382 Pearson Thompson Oreily Prentice Hall PURCHASE ClienLd Bookcode PublisherName Cost 123 B1 Pearson 100.00 123 B4 Oreily 65.00 123 B5 Thompson 86.00 124 B5 Thompson 90.50 125 B1 PrenLce Hall 125.40 125 B2 Pearson 94.50 125 B5 Thompson 75.00 13 Use the RETAIL STORE database of Fig 3 to answer the next few questions. Question 3: (total marks = 20 for 10 + 10) Using the Retail store Database of Fig. 3, answer the following questions by expressing the queries in: (i) SQL, (ii) Relational algebra (RA), (iii) Relational Calculus (RC) as well as showing the, (iv) result of each query. Note: specify any needed aggregate function or group by attributes within your relational calculus and algebra queries appropriately by specifying those aggregate function and group by in the regular RC query even if it does not have a function to represent it usually. (a) Retrieve the publisher names (Pname) and their phone numbers (PPhone), book author (author) for books that are Purchased and with cost of more than $90. (10 marks) (b) For each book, list the book title and the minimum purchase cost for this book. For example, the minimum purchase cost for the book B5 is $75. (10 marks) ** Some symbols that may be useful for copying are: σ, π, ! , -:-, , ∃, ∀ , Que 3 (10 marks for each of a and b ) 14 (a) Query in SQL, Relational Algebra, Relational Calculus, Result (10 marks) (a) Retrieve the publisher names (Pname) and their phone numbers (PPhone), book author (author) for books that are Purchased and with cost of more than $90. SQL: Relational Algebra: Relational Calculus: Query Result: 15 (b) Query in (b) For each book, list the book title and the minimum cost for this book. For example, the minimum cost for the book B5 is $75. SQL, Relational SQL Algebra, Relational Calculus, Result (10 marks) Relational Algebra: Relational Calculus: Result: 16 Question 4 : (total marks = 10 for 5 + 5) (a). Given the following B-tree of order p=3 which has already inserted into it the values 15, 60, 34, 11 you are required to insert into it, the sequence of ids 29, 83, 37 and show: (i) the steps for inserting the given sequence of unique ids for some database records of a relation, and (ii) the final B-tree index structure of order p=3 (or with maximum of 3 pointers) after the insertions. B-tree is used for speeding up retrieval of records from their primary data file stored on disk. Show the steps through arriving at your final tree before giving your final tree. (5 marks) 34 11 15 60 For (a): Starting B-tree of order p=3 Solution (a) (5marks) Give each step of the insertion of 29, 83, 37 into the B-tree with already 15, 60, 34, 11 inserted. Step 1: insert 29 into the above B-tree to get: Step 2: insert 83 into the above B-tree from step 1 to get: 17 Step 3: insert 37 into the above B-tree from step 2 to get: This is the final B-tree after inserting 29, 83, 37 into B-tree with 15, 60, 34, 11. (b). Given the following B+-tree of order p=3 (and p-leaf of 2), which has already inserted into it the values 15, 60, 34, 11, you are required to insert into it, the sequence of ids 29, 83, 37 and show: (i) the steps for inserting the given sequence of unique ids for some database records of a relation into the B+-tree, and (ii) the final B+-tree index structure of order p=3 (or with maximum of 3 pointers) after the insertions. B+-tree is used for speeding up retrieval of records from their primary data file stored on disk. Show the steps through arriving at your final tree before giving your final tree. (5 marks) 15 11 15 34 34 60 For (b): Starting B+-tree of order p=3 (and p-leaf = 2) Solution (b) (5marks) Give each step of the insertion of 29, 83, 37 into the B+-tree with already 15, 60, 34, 11 inserted. 18 Step 1: The following shows the B+-tree after insertion of 29. Step 2: The following shows the B+-tree after insertion of 83. Step 3: The following shows the B+-tree after insertion of 37. 19 This is the final B+-tree after inserting 29, 83, 37 into B-tree with 15, 60, 34, 11 20