Display the data using the customer table

Assignment Help Database Management System
Reference no: EM131097796

Task

Your final task is to use your tables for an update and for reports. There are two requirements.

1. You will demonstrate an update that includes two tables and uses a subquery. Make sure to prove that your update executed correctly by showing data in the tables before and after the update.

2. You will also develop at least four meaningful reports. One must include a join, one must use a subquery, and one must use an aggregate function. You need to describe the business requirement of the update and each report. Note that numeric PK values are not often meaningful to a person looking at the report.

You will create a script file that has each of the queries called yourname_task3.txt. You will also document the results of this task in a Word document called yourname_reports.docx to show the result of each query. For the update and each report,

• describe the update and report requirement;
• show the query; and
• show the result of the query.

Include a final section for Conclusions and Lessons Learned regarding the project.

Note that your deliverables each week include any revisions to a previous task.

Submit your Task deliverable as a zip file including the following.

• Task 0 proposal (with any revisions)
• Your Task 1 ERD (with any revisions)
• Your Task 1 DD (with any revisions)
• Your Task 2 script file to create and populate tables (with any revisions)
• A Word document showing all tables and data (with any revisions)
• Your Task 3 script file with update and reports (yourname_task3.txt)
• A Word file with results of Task 3 and lessons learned (yourname_reports.docx)

Lab: Working with Views

LAB OVERVIEW

Lab will introduce the concept of database views.This lab may be completed using either DeVry's Omnymbus EDUPE-APP lab environment, or a local copy of the MySQL database running on your own computer using the OM database tables. The lab will utilize a set of tables that are represented by the ERD (OM_ERD.docx) and are created and populated by the script file (create_OM_db.sql). Follow the instructions in the file CreateOMTables.docx to create your database, tables, and data.

A few IMPORTANT things to note if using EDUPE MySQL:

**There can be NO SPACES in alias names given to a column. For example:
Select unit_price as "Retail Price " from items; --this does NOT work in EDUPE MySQL.
Any of the following WILL WORK:
Select unit_price as "RetailPrice" from items;
Select unit_price as "Retail_Price" from items;
Select unit_price as Retail_Price from items;
Select unit_price as RetailPrice from items;

**Any calculated fields MUST be given an alias (and note above NO SPACES in alias). For example:
selectunit_price * 2 from items; --this does NOT work in EDUPE MySQL

This will work:

selectunit_price * 2 as NewPricefrom items;

Deliverables

• Lab Report (Answer Sheet) containing both the student-created SQL command(s) for each exercise, and the output showing the results obtained. Be sure your name is on the file.

LAB STEPS: Complete each of the exercises below.

1. Use an ALTER TABLE statement to update the customers table so that the Primary Key field is an auto-increment field, then create TWO insert statements to test proper operation, using your own first and last name for one (and a name of your choice for the second one), and any data you care to imagine for the remaining fields.

IMPORTANT NOTE: When using a LOCAL copy of MySQL, if you attempt to simply issue the ALTER TABLE command you have composed by itself, you should receive an error similar to the following (try it for yourself!).

ERROR 1833: Cannot change column 'customer_id': used in a foreign key constraint 'orders_fk_customers' of table 'om.orders'
(Note - EDUPE will not give this error message, however you should still follow the CORRECT procedure as discussed here to complete this problem).

The reason for this is that you are attempting to alter data in one column that has a defined PK:FK relationship to a field in another table. Referential Integrity rules prevent this. So, how do you resolve such a problem?

One approach to solving this dilemma is to turn off the foreign key checks that implement referential integrity rules.However, the danger here is that other users and processes operating on the database while these constraints are suspended could create or modify data in a way that compromises integrity. We can solve this second problem by preventing other users and processes from altering the data in the table in which we are working until we have turned the foreign key checks back on. We therefore need to construct a script that does the following.

a) Locks the customer table -- lock table customers write;
b) Turns off FK checks -- set foreign_key_checks = 0;
c) Alters the table to add the auto_increment feature to the PK field
d) Turns FK checks back on -- set foreign_key_checks = 1;
e) Unlocks the customer table -- unlock tables;

It is VERY important to consider that altering tables can require a bit of time for very large tables, and that while the table is locked, other users and processes cannot operate. Consequently, this kind of modification should not be done during peak operating hours in a production operation (as a student in a lab exercise, working on your own database, you may do this at any time) but ideally in hours during which the business does not normally operate. In cases where round-the-clock, high availability of a database is required, other approaches may be required.Addressing this problem in a high-availability, high-demand environment is an advanced topic, study of which is outside the scope of this course.Use the outline below to construct your script. Show all commands in your answer sheet along with the output of the commands.

lock table customers write;
setforeign_key_checks = 0;

-- Replace this comment with your ALTER TABLE command to add the auto_increment feature to the PK field

setforeign_key_checks = 1;
unlock tables;

--statements to insert two rows into the table
--verify auto_increment with a select statement

2. The Vice President of Marketing for your firm wants the firm's sales representatives to be able to directly view and edit customer details, but only for the state to which a particular sales representative is assigned. You have suggested that this need can be addressed with a view. For example, a view could be created for one particular state, and user account permissions for accessing that view granted only to sales representatives from that state. The VP has asked you to quickly create a simple proof-of-concept demonstrating how this might work.

Complete the following steps:

a. Construct a view on the customers tablecalled CA_CUSTOMERS that consists of all data about customers that live in California.

b. Display the data using this view to verify that only customers that reside in California are visible.

c. Prove that It is possible to add or update records through this viewby updating the record for Karina Lacy to change the spelling of Karina's last name to Lacie.

d. Display the data using the customer table to verify that the change has been made.

Show all commands in your answer sheet along with the output of the commands.

3. The Senior Customer Service Manager has requested the ability to create a report at any time that will show shipped orders that took some specified number of days to fulfill.

a. Create a view named SHIPPING_TIME that lists only customer_first_name, customer_last_name, order_date, shipped_date, and the calculated field days_to_fulfill(use the DATEDIFF function) showing the number of days between when the customer placed the order and when it was shipped. Show the data from this view.

Now let's do some queries by adding sorting and filtersUSING THIS VIEW, WITHOUT CHANGING IT.

b. Use the view to display the data sorted by highest to lowest days to ship

c. Use the view to display only the orders that took less than 10 days to ship.

d. Use the view to display only the orders that took more than 30 days to ship.

4. Queries that require joins and aggregate functions can be easier to construct when using a view as a "temporary" table. Consider a report to show total sales by artist.

a. First create a view called SalesData that displays the order_id, item_id, the calculated field ItemTotal (which is quantity times price), the title and artist_id.

b. Display the data in the SalesData view sorted by artist_id. Does this help you to "visualize" how to group the data to create the totals?

c. Create a query USING THIS VIEW and the appropriate aggregate function to display artist_id and the total sales for each artist.

d. Now join to the artist table in order to display the artist_name along with the total sales.

5. Now use this same method to display the total sales per customer.

a. Create a view called SalesData with the appropriate data. At a minimum you will need customer_id and the calculated item total. DO NOT use the customer table in this view, it will be joined later.

b. Display the data in your view sorted by customer_id. Does this help you to "visualize" how to group the data to create the totals?

c. Create a query USING THIS VIEW and the appropriate aggregate function to display customer_id and the total sales for each customer.

d. Now join to the customer table in order to display the customer_name as a single field named Customer along with the total sales. Sort the report by Total sales in descending order.

Reference no: EM131097796

Questions Cloud

Role of women in death of a salesman by using an approach : Write a research paper about the role of women in death of a salesman by using an approach on the feminist point of view in the play. Paper should be 7 full pages not counting work cited page
Focuses on pricing and exchange rates : This question focuses on Pricing and exchange rates: On January 1, the U.S. dollar: Japanese yen exchange rate is $1 = ¥250. During the year, U.S. inflation is 4% and Japanese inflation is 2%. whose toughest competitor is Japan's Komatsu in the US ma..
Determine student learning and lesson effectiveness : Define the terms "bullying" and "cyberbullying", and specify the main difference(s) between these two terms -  determine student learning and lesson effectiveness
Communicate information about employee benefits : Why is it important to communicate information about employee benefits? Suppose you work in the HR department of a company that has decided to an additional two days of paid you recommend communicating this change?
Display the data using the customer table : Display the data using the customer table to verify that the change has been made. Construct a view on the customers tablecalled CA_CUSTOMERS that consists of all data about customers that live in California.
Write a narrative-descriptive essay : Directions: use a moment of fear, anxiety, embarrassment, awe, joy, sorrow, or other strong emotion. Think about what happened, how you got into the situation and out of it.
Calculate the price elasticity of demand : Current average daily sales of hats are 60. The current price is $9.24 per hat. A store manager notices that a rival store is charging $8.50 per hat. Use the mid-point method to calculate the price elasticity of demand.
What are the four phases of the business cycle : What are the four phases of the business cycle? Why is it difficult to distinguish between frictional, structural, and cyclical unemployment? Why is unemployment an economic problem? What are the consequences of a negative GDP gap? What are the nonec..
Identify single-variable unconstrained minimization problem : Identify a single-variable unconstrained minimization problem relevant to engineering. That is, your minimization should arise in the solution of some real-world, physicallybased design or analysis problem

Reviews

Write a Review

Database Management System Questions & Answers

  Write set of relational schemas-identify primary-foreign key

Sketch an E-R diagram which reflects the above reuirements. Write a set of relational schemas and identify primary and foreign keys. Try not to include redundant schemas.

  Discussed and implemented the mvc design pattern

Find another design pattern which could be used for web based development and write a synopsis on it, pointing out whether it would be applicable for use within your project or not. Comment as applicable on design patterns that other class members..

  Create a mysql database

Create a Database and modify your script to reference your Database. Download the tutorial Creating a Database in MySQL Omnymbus Environment from the folder in Doc-Sharing titled Omnymbus Tutorial Files. Follow the steps to create a database in MyS..

  What benefits could be gained from using a team to develop

describe the advantages and challenges of using a team to develop a microsoft access database. assignment guidelines

  How the knowledge and skills taught on the module and course

Each student should submit his or her own critical assessment of the coursework. The evaluation should include a discussion on how the coursework has reinforced (or otherwise) his or her appreciation of the techniques and processes employed in undert..

  Print to screen the ''below average''

Print to screen the 'below average' if minimum unit_cost is 10 for the same product (use sh.costs table)

  Explain data for each candidate of eight constituencies

supplies % of votes each candidate is likely to receive, based on popularity rating. Actual number of votes received is that percentage of General votes. You should enter data for each candidate in each of the eight constituencies.

  Gathering information using cross indexed

Using data mining, it is possible to gather information which has been buried that can be manipulated and cross indexed which could be a valuable information gathering technique for entities.

  Design a collection of tables that satisfies 2nf but not 3nf

Using the FD list in problem 1, identify the FDs that violate 2NF. Using knowledge of the FDs that violate 2NF, design a collection of tables that satisfies 2NF but not 3NF.

  What is the two-phase locking protocol

What is the two-phase locking protocol and what is the strict two-phase locking protocol? What is the rigorous two-phase locking protocol? What benefit does strict two-phase locking protocol provide? What benefit does rigorous two-phase locking pr..

  Develop a use case for each of the major processes

Develop a Use Case for each of the major processes and create the context diagram for the system described.

  Optimizing sql server query performance how to optimizing

how to optimizing sql server query performance? when optimizing your database server you need to tune the performance

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd