Starting from:
$30

$24

Homework Number Three SQL

Overview

This Project is worth 150 points (150 out of 1000, or 15%) toward your final grade. It is due on Sunday, October 9, at 11:59 p.m. Late submissions will be penalized 20% during a 3-day grace period up until Wednesday, October 12, 11:59 p.m. After that time, no late work will be accepted. Your submission should be a document saved and submitted as a PDF file via the link found in the assignment section of the Week Five module in Canvas which is the same place where you found this file.

This assignment will give you hands-on practice in working with MySQL and the SQL language. In this Project you will create a database and populate it with data using the scripts provided. You will use the database you create for running a variety of queries and answering a few questions.

This assignment is NOT available for group work. You must do your own work on this project.

Objectives

    1. Become familiar with the SQL language & syntax for SELECT queries, DDL and DML

    2. Become familiar with a tool of your choice for building and submitting queries (whether command mode or GUI.)

    3. Successfully run the scripts necessary to create a sample database, verify that your database is correctly built.

    4. Run SQL queries against your database to answer the assigned problems.




Step One: Downloading and Installing MySQL

For this project assignment you will need to download and install MySQL Community Edition on your computer. If you already did this when you installed MySQL Workbench, then you can skip this section.

Your download/install will depend on what type of computer you have and what Operating System it is running.

You will want to download MySQL Community Server 8.0.* The current release number changes from time to time. If for some reason you don’t want to use version 8.0 – for example if you already have version 5.7 running on your computer, you can use version 5.7.x. Either version will work fine.

Do NOT download “MySQL Cluster” software -- similar name, but a VERY different DBMS product.

 
CSCI3287 Database Systems

Homework Number Three – SQL



This page (below) contains online documentation links where you can find help with the download and installation if you need it.

The download you need can be found here: https://dev.mysql.com/downloads/mysql/

Choose the download file that matches your computer’s OS and version.

Once you have downloaded and installed MySQL, you should launch the MySQL instance so that it is running in the background on your computer.

Step Two: Choose Your Preferred Query Editor Tool

In order to create SQL queries and run them against your MySQL database, you will need a tool or a user interface through which you can create and execute queries, and then view/copy/export the answer set.

The default is the mysqld command line interface. This command line interface is installed with MySQL and is similar to using the Linux shell. If you choose to do your queries via the MySQL command line interface, you do not need to download/install any query tool.

However, managing and running queries against MySQL databases is simpler, faster and easier if you use a GUI (graphic user interface) tool. There are many available.

You can use MySQL Workbench. You have seen your instructor use MySQL Workbench in class to create an ERD (Entity Relationship Diagram) data model and then generate SQL to create tables. Your instructor also used MySQL Query Editor to demonstrate SQL commands during those lectures on the SQL language. MySQL Workbench is free. You can use MySQL Workbench to build and submit queries against your database. It is available here: https://dev.mysql.com/downloads/workbench/ You probably already installed MySQL Workbench for Homework # 2.

MySQL offers versions for Windows, Linux, MAC.

A great open source alternative to MySQL Workbench is DBeaver. The community edition is free and it comes with versions for many different OS builds and works fine with MySQL. https://dbeaver.io/download/

Another alternative for MAC users is DataGrip. https://www.jetbrains.com/datagrip/ They offer a free 30-day trial, and a special free edition for students that you can sign up for.

 
CSCI3287 Database Systems

Homework Number Three – SQL


Step Three: Creating the Database

Once you have selected your query editor, you need to download the “ClassicModelsCreate” script file from Canvas, Week Five module, then unzip it and execute it. It will create your database and tables, and then load the tables with data. The script runs fine as-is without any modification.

Before you can create your database, you need to make sure that your instance of MySQL is running in the background.

Then using your query editor, you must connect to the running MySQL instance prior to running the script.

HINT: You should download and print this ERD (below) and keep it handy when you are writing your queries. It is very helpful to have table and column names in front of you when writing SQL queries.



MySQL Sample Database Schema


The MySQL sample “Classic Models” database schema consists of the following tables:

Customers Products ProductLines Orders OrderDetails Payments Employees Offices

customer data.

a list of scale model cars.

a list of product line categories.

sales orders placed by customers.

sales order line items for each sales order.

payments made by customers based on their accounts

employee information including the organization structure such as who

reports to whom.

sales office data.



 




















































Note: GUI Query Editor Users: After you run some queries to create your tables, you might expect the new tables to immediately appear under the “object explorer” on the left side of your GUI query editor. They will eventually show up, but to see them appear right away, you will need to click on the “refresh” icon (if your tool has one.) If this icon does not appear, then click somewhere







CSCI 3287 Database Systems    Page 4
CSCI3287 Database Systems

Homework Number Three – SQL



within your “object explorer” and the newly created tables should appear. (Depends on your query tool…)

If you are using the command line editor, you can enter SHOW TABLES and MySQL will show you all the tables in your database.

After running the unzipped script file to create and load your database, you should run the following “Verify” script to ensure that your database is built correctly.

Verify Script:


SELECT table_schema, table_name, table_rows

FROM information_schema.tables

WHERE TABLE_SCHEMA LIKE 'classic%';



You should see the following tables and row counts for your Classic Models database.
table_schema
table_name
table_rows



classicmodels
customers
122



classicmodels
employees
23



classicmodels
offices
7



classicmodels
orderdetails
2996



classicmodels
orders
326



classicmodels
payments
273



classicmodels
productlines
7



classicmodels
products
110






Preparing Your Assignment Submission

Your results for this homework assignment should be captured in a document (such as a .txt file, MS Word or similar tool.) Please then save your final deliverable document as a PDF. Your submission should be a document saved and submitted as a PDF file via the link found in the assignment section of the Week Five module in Canvas which is the same place where you found this file.





CSCI 3287 Database Systems    Page 5
CSCI3287 Database Systems

Homework Number Three – SQL




You must turn in BOTH your SQL Code and your ANSWER SET (unless otherwise specified.)

For each problem where a multi-row answer set is created, the number of rows you should expect in your answer set is listed in parentheses after the problem/question. Some queries will product NO answer set.

Please copy/paste the SQL and the answer set for each problem and number them so that the graders can easily find and understand your submission.

Query Problems

For this project you must create and execute queries against the ClassicModels database to fulfill the requirements listed below. For each query requirement, as a “hint”, the number of rows to expect in your answer set is listed in parentheses.

    1. List the countries in ascending alphabetical order where Classic Models has offices. (5)

    2. List the EmployeeNumber, LastName, FirstName, Extension for all employees working at the San Francisco office. (6)

    3. List the ProductCode, ProductName, ProductVendor, QuantityInStock and ProductLine for all products in the Vintage Cars product line with a BuyPrice between $50 and $60. (4)

    4. (Use a SUBQUERY) List the ProductCode, ProductName, ProductVendor, BuyPrice and MSRP for the least expensive (lowest MSRP) product sold by ClassicModels. (“MSRP” is the Manufacturer’s Suggested Retail Price.) (1)

    5. What is the ProductName and Profit of the product that has the highest profit (profit = MSRP minus BuyPrice). (1)

    6. List the country and the number of customers from that country for all countries having more than 6 customers. List the countries sorted in ascending alphabetical order. Title the column heading for the count of customers as “Customers”. (4)

    7. List the ProductCode, ProductName, and count of orders for the products supplied by Welly Diecast Productions. Title the column heading for the count of orders as “OrderCount”. (8)

    8. List the EmployeeNumber, Firstname + Lastname (concatenated into one column in the answer set, separated by a blank and referred to as ‘Name’) for all the employees reporting to William Patterson or Mary Patterson. (7)





CSCI 3287 Database Systems    Page 6
CSCI3287 Database Systems

Homework Number Three – SQL



    9. List the EmployeeNumber, LastName, FirstName of the CEO of the company (the one employee with no boss.) (1)

    10. List the ProductName for all products in the “Motorcycles” product line from the 1990’s. (3)

    11. When customers place orders, they indicate when they need to receive the merchandise they purchased. (Orders.RequiredDate). Create a report that shows orders shipped in November 2004 that were shipped less than 3 days before their required date. (8)

    12. List the firstname, lastname of employees who are Sales Reps who have no assigned customers.

(2)

    13. List the customername of customers from Switzerland with no orders. (2)

    14. List the customername and total quantity of products ordered for customers who have ordered more than 1700 products across all their orders. (6)

        15. Create a NEW table named “TopCustomers” with four columns: CustomerNumber (integer), ContactDate (DATE), OrderCount, (integer) and OrderTotal (a decimal number with 9 digits in total having two decimal places). None of these columns can be NULL. Include a PRIMARY KEY constraint named “TopCustomer_PK” on CustomerNumber. (no answer set)

    16. Populate the new table “TopCustomers” with the CustomerNumber, today’s date, and the total count of all their orders, and the value of all their orders (PriceEach * quantityOrdered) for those customers whose order total value is greater than $150,000. (inserted 7 rows, no answer set)

    17. List the contents of the TopCustomers table in descending Order Value sequence. (7)

    18. Add a new column to the TopCustomers table called CreditRating (integer). (No answer set)

    19. Update the Top Customers table, setting the CreditRating column to a random number (from 0 to 9). (Should update 7 rows) HINT: use the RAND() and FLOOR() functions. (No answer set)

    20. List the contents of the TopCustomers table in descending CreditRating sequence. (7)

    21. Drop the TopCustomers table. (no answer set)











CSCI 3287 Database Systems    Page 7

More products