hw3
hw3
hw3
This will give you an opportunity to read the create_database.sql script as well as
execute the script. Execute the script by hitting the lightning rod icon in the MySQL
workbench.
Review the action output response to verify that the multiple commands ran
successfully. The response is written to the panel underneath the editor SQL script
panel. Make sure you can differentiate between success messages, warnings, and
error messages. If you do not have enough memory to load the script into the editor,
import the script using the import tool (Server → Data Import). While importing,
specify that the script is a self-contained import file. Read the script using your
favorite editor. Familiarize yourself with the database names, the table names, and the
table structures. Identify the SQL commands, CREATE, USE, INSERT, DROP (0
Points).
2. Answer the following questions on the newly created databases. These answers can
be determined by reading the results in the Output window, investigating the tables
using the i icon listed in the navigator panel next to the table, or by writing simple
queries. Include the answers to questions a-h inside a comment within a file called
hwk3problem2and5lastnamefi.sql, where lastname is your last name and fi is the
initial for your first name. For i and j, write SQL queries to answer the following
questions on the om database. Include a comment that specifies the problem number
before each SQL statement i.e. 2.e, 2.f (30 points)
1. How many databases are created by the script?
2. List the database names and the tables created for each database.
3. How many records does the script insert into the om.order_details table?
4. How many records does the script insert into the ap.invoices table?
5. How many records does the script insert into the ap.vendors table?
6. Is there a foreign key between the ap.invoices and the ap.vendors table?
7. How many foreign keys does the ap.vendors table have?
8. What is the primary key for the om.customers table?
9. Write a SQL command that will retrieve all values for all fields from the
orders table
10. Write a SQL command that will retrieve the fields: title and artist from the
om.items table
3. Create a model for the ap database. You can access the modeling tool from either the
‘Database → Reverse Engineer’ menu item or from the main home window on My
SQL workbench. Familiarize yourself with the different shapes found within the
model diagram. For example, the different lines and endpoints to the lines. Move the
rectangles that represent the tables to eliminate line crossings. Once you are satisfied
with the image, save the model to a file named hwk3problem3lastnamefi.mwb and
export the model as a pdf file named hwk3problem3lastnamefi.pdf. (20 points)
4. Export the om database as a self-contained file using the tool (‘Server→ Data
Export’). Make sure you include the ‘Create Schema’ as part of the dump as well as
to make the dump a self-contained file. Name the file hwk3problem4lastnamefi.sql
(20 points)
5. Import the chinook database (follow the same procedure from 1 for chinook.sql file).
Answer the following questions on the newly created chinook database. These
answers can be determined by reading the results in the Output window, investigating
the tables using the i icon listed in the navigator panel next to the table, or by writing
simple queries. Include the answers to questions a-d inside a comment within a file
called hwk3problem2and5lastnamefi.sql, where lastname is your lastname and fi is
the initial for your firstname. For e and f, write SQL queries to answer the following
questions on the chinook database. Include a comment that specifies the problem
number before each SQL statement i.e. 5.e, 5.f (30 points)
1. How many tables are created by the script?
2. List the names of the tables created for the Chinook database.
3. How many records does the script insert into the Album table?
4. What is the primary key for the Album table?
5. Write a SQL SELECT command to retrieve all data from all columns and
rows in the Artist table.
6. Write a SQL SELECT command to retrieve the fields FirstName, LastName
and Title from the Employee table