讲解:CSC 321/621、SQL、SQL、ISBNDatabase|Python

CSC 321/621 – Spring 2019Test 1 – Take Home PortionYou may access textbooks and course materials but the WORK SUBMITTED MUSTBE DONE BY YOU AND YOU ALONE! No communication regarding these questionswith anyone real or virtual. No Exceptions. I reserve the right to ask you to explainyour responses orally if I have a question about your response.I will try to clarify any questions you have. Send your questions in e-mail. I’ll broadcast aresponse as quickly as possible. Please submit your responses on paper (printed orhandwritten) at the start of class on Tuesday. The deadline is 12:30pm next Tuesday, 2/19/19.Setup:Download the following files: Resources ? Test 1 Materials ? { yadkin.db, make-yadkin.sql } from Sakai.You will need to open the yadkin.db database in SQLite Studio to write and check queries. The file namedmake-yadkin.sql contains the SQL code used to create the database schema. You will only need to open it ina text editor, not in SQLite Studio.Explanations regarding Yadkin:- Regarding the author table. The attribute “SEQUENCE_NUMBER” has to do with the order that theauthors are listed by when a book has multiple authors. Values can be 1, 2, …, for “first author”, “secondauthor”, …- The ISBN values are not realistic but don’t worry about it …- The invent table name is short for “inventory.” It tracks the books available at a branch. Not all booksare available at all branches; furthermore, some books may not be available at any branch.- The book table has an attribute named PAPERBACK that will contain ‘Y’ if the book is available as apaperback. The value may also be ‘N’ to indicate it’s a Hardback book or null to indicate unknown.I. (10 pts) Open make-yadkin.sql in a text editor and/or use sqlite to answer the following questions.1. List the names of the tables in the yadkin database along with the primary key of each table.2. List the foreign keys in the database, identifying both the source of the foreign key and the referencedtable and column(s).3. Use the results of the previous two questions to sketch the database schema. That is, create arectangle for each table, identifying the attributes and identifying primary key with an underscore anddrawing lines between tables to represent foreign keys.II. (30 pts) For each of the prompts below, write an SQL query to retrieve data from or to modify the“yadkin” database.In your response, label each query clearly and precede each one with a very brief description of what youbelieve your query does. For example you might write: “This query uses a natural join to relate books totheir authors. It then selects those authors who have written more than 10 books.” Prompts:a. List the titles of all books published by a publisher located in New York (‘NY’). Don’t repeatany titles.b. List the titles of CSC 321/621作业代写、代写SQL编程语言作业、SQL实验作业代做、代写ISBN留学生作业 代写Databasethe books that have exactly two authors. Don’t repeat any titles.c. Find the average price of all the paperback books that are included in the book table. Paperbackbooks have a value of ‘Y’ in the “paperback” attribute of book.d. List the titles of the books in the book table that are available in both paperback AND hardbackform.e. List the names of the books that are out of stock at all branches (a book is out of stock if theunits_on_hand in inventory = 0 at all stores or if just doesn’t show up in the inventory table).f. List the name(s) of the branch with the smallest number of employees (might not be unique).g. List the name of every branch along with the total value of the inventory at that branch. The valueof the inventory is determined by the units_on_hand times the book_price.h. List the name of the branch with the highest inventory value. Your query should work correctlyeven if the data in the tables changes.i. In a single table, list the name of every branch along with a list of all the publishers (frompublisher) and the number of books from that publisher that the branch has in inventory, even if itis zero. HINT: If there are 5 branches and 10 publishers in the database, the resulting table shouldcontain 5 x 10 = 50 rows.j. List the name of every branch along with the name of the lowest price book currently in inventoryat that branch. A book is in inventory at a branch if the units_on_hand for that branch is greaterthan 0.III. SQL View, etc. exercises (10 pts)i. You may have discovered that the inventory table is “incomplete” in that not every book is listed in theinventory table for every branch. Let’s fix that. Write an INSERT INTO statement that will make theinventory table complete. That is, if there is a book that is not listed in the inventory table for a branchthen insert a value of 0 for UNITS_ON_HAND for that book at that branch. After your query executesthe number of rows in inventory should be exactly the product of the number of rows in BOOK and thenumber of rows in BRANCH.ii. Write the SQL statement to create a view on the Yadkin database named book_info containing, for eachunique ISBN, a single row made up of the book_title, publisher_name, book_price, and a count of thenumber of authors of the book.(Grad students only)iii. Let’s say that instead of “a count of the number of authors” of each book we wanted to create a view thatcontained a list of the last names of all the authors for each book. So we want to see, for each uniqueISBN, a single row made up of the book_title, publisher_name, book_price, and a list of the last names ofthe authors. Explain why this would be a difficult task to do in SQL. Could a recursive query be used?Would that be all you need? You don’t need to write any SQL for this question, just your ideas.转自:http://ass.3daixie.com/2019022018336100.html

你可能感兴趣的:(讲解:CSC 321/621、SQL、SQL、ISBNDatabase|Python)