Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DBMS Expert


Home >> DBMS

SQL Query Assignment -

For this assignment you are to write your answers in a word document. This assignment is in three parts: Part A (reporting queries), Part B (query performance), Part C (query design).

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the FinanceDB database unless specifically stated otherwise.

Part A - FinanceDB Reporting Queries

You are to work on a series of questions that help the Finance team understand their regional sales performance. Use the FinanceDB database to answer each of the following questions with an SQL query.

Section 0:A - A database backup for FinanceDB is available. Download this backup and restore it to your SQL Server instance. Once it has restored, provide a screenshot that shows the FinanceDB database in your SQL Server Object Explorer.

Section 0:B - All t-SQL follows the appropriate style as per all class examples.

Section A - Query Writing

This section has a series of questions which will require you to a) write a t-sql query, b) produce some basic visualisations using Power BI and c) provide brief answers to short answer questions.

You should include all t-sql (copy and paste and then format it so that it is easy to read) and screenshots of any visualisations you create.

Query one - This company has a presence in 5 countries across 5 industries (Segments) within each country. Calculate the total sales per year and the total profit per year for each Country / Segment. Note that profit can be calculated:

1A: Run this query and include a screenshot of the results.

1B: Produce one or more visualisations using PowerBI to display this information.

Based on your visualisations, which region performed the best? Which region performed the worst?

Query two -

 2A: Each sales person has a yearly sales KPI. This is their yearly sales target which they are expected to meet. I'd like you to use this information to calculate a yearly sales KPI for each Country and Segment:

2B: Once you have calculated this KPI, calculate the yearly performance against the KPI (i.e. if the KPI for Mexico, Midmarket is $100,000 and the total sales was $110,000, then the yearly performance would be 110%). Include your t-sql below.

2B: Produce one or more visualisations in PowerBI to show this information.

Query three -

3A: A lot of information about sales performance is lost when it is aggregated yearly. Change your query from (Query Two 2B) to calculate the month-by-month total sales performances and plot these data in PowerBI.

3B: What general conclusions can you draw from this visualisation? Justify your reasoning.

Query Four - Finally, the company wants to reward the best performing sales people. But they don't really know what they mean by "best performing".

4A: Explain how could you rank & compare each salesperson's performance?

4B: Create a query & one or more visualisations that allows the company to explore the performance of their salespeople. Include the t-sql and a screenshot of the visualisations below.

4C: Using your results, which salespeople do you believe are the "top 10 best performers"?

Section B - Query Performance and indexing

This section has a series of questions which will require you to review query execution plans and design appropriate indexes to improve the performance of these queries.

You should include all t-sql (copy and paste and then format it so that it is easy to read) and screenshots of relevant parts of the execution plans where appropriate

Question B1 - Run the following (attached) query and review the execution plan:

B1A: What are the most expensive operations in this query execution plan? Include the relative cost of each operation you identify.

B1B: What is a clustered index scan? Why can this be a problem for performance? When would it not be a major concern?

B1C: Design an index to remove the clustered index scan on SalesOrderLineItem. Include the t-sql you used to create the index.

B1D: After creating your index, review the execution plan again. Did this index substantially reduce the relative execution cost of querying data from SalesOrderLineItems?

B1E: Describe what indexes are used for and when they improve query performance.

B1F: In what situations would you limit the number of indexes you have on a table and why.

B1G: Explain whether you would keep the index you created in B1C.

Question B2 - Review the following (attached) query:

B2A: In simple terms, explain the business question which this query is addressing.

B2B: A developer has suggested creating the following index to improve the query: create index idx_promotions on SalesOrderLineItem (PromotionID, SalesOrderID);

Review the execution plan before creating the index. What part of the execution plan do you think the developer is trying to improve? Include a screenshot of this part of the execution plan.

Create the index and review the execution plan again. Has the index improved this part of the execution plan? Explain why.

Drop this index and create a suitable index to improve the execution of this query. Include a screenshot of the new execution plan.

Has your index improved the part of the execution plan that you expected it to? (i.e. has it substantially decreased the execution cost of this part of the plan?). If so, why? If not, what has it done?

B2C: Have a careful look at the results from the query above. Notice that there is a row for each Country / Segment every month. Adjust this query so that it only returns the Country / Segment with the highest TotalMonthlySales in each month. You should get 12 rows.

Note that there are a few different ways that you could write this query and get the correct result.

Include your query below and a screenshot of the results.

Section C - Query Refactoring

This section has one question which requires you to first understand and then refactor a badly performing query. You should try to simplify this query as much as possible, balancing readability and performance. You should investigate potential indexes to improve the performance of this query.

Note that this query is very similar to a real query that I had to refactor for a client a number of years ago. It's not always easy... Take your time and try to break it down into small pieces. Aim to understand all the small parts and then combine them back up to create the big picture.

While I was creating this question, the original query took ~40 seconds to run on my laptop. After my changes, I was able to get my revised query down to < 2 seconds.

You should include all t-sql (copy and paste and then format it so that it is easy to read) and screenshots of relevant parts of the execution plans where appropriate

To maximise their future profits, the Marketing Team need to be able to track the margin (profitability) and discount on all orders in real-time . They have had a business analyst attempt to write a SQL query which tracks information about every order. An example of the output of the query is shown below for you:

Unfortunately, the business analyst's query is way too slow to run in real time. The analyst's query is available from here. Your job is to rewrite this query so that it is scalable (can run over large amounts of historical data and is quick enough to run in real-time).

Question CA: Review the query execution plan and clearly describe why this query will not scale well.

Question CB: Rewrite this query so that it is scalable. Include your t-sql code below.

Question CC: Run both the original query and your version of the query. Review the execution plans of both queries. Make any additional changes that will improve the performance of this query.

Explain simply how has the execution plan changed from the original query to your query?

Make any additional changes (for example indexing) that you think would help. Include the t-sql for these changes below.

Run both queries together and include a screenshot that shows the relative costs of both queries.

Include a screenshot of the execution plan of your query after all changes have been applied.

Attachment:- Assignment File.rar

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M93108089

Have any Question?


Related Questions in DBMS

Question create the physical data model for the logical

Question: Create the physical data model for the logical data model that you submitted in IP3. This should include all of the data definition language SQL. Your submission should include all DDL needed to: Create the tab ...

Question 1 describe 1nf 2nf 3nf2 explain why 4nf is a

Question: 1: Describe 1NF, 2NF, 3NF. 2: Explain why 4NF is a normal form more desirable than BCNF. The response must be typed, single spaced, must be in times new roman font (size 12) and must follow the APA format.

Question team project submission - submit to the unit 4

Question: Team Project Submission - Submit to the Unit 4 Group Project Area This version of the capstone project assignment is FOR GRADING this week. Submit to the group area the document containing completed Sections On ...

Question sql injection is in the top 10 owasp and common

Question : SQL Injection is in the top 10 OWASP and Common Weakness Enumeration. Using MySQL and PHP, show your own very short and simple application that is vulnerable to this attack. Provide another version that mitiga ...

Answer the following question explain the difference

Answer the following Question : Explain the difference between a database management system (DBMS) and a database. Are Microsoft Access, SQL Server, and Oracle examples of databases or database management systems (DBMS)?

A schools office of the registrar maintains data about the

A School's office of the registrar maintains data about the following entities: a) courses (including course number, title, credits, syllabus and prerequisites), b) course offerings (including course number, year, semest ...

In sql database questions phase-1 in 100 words what steps

In SQL Database Questions: Phase-1 In 100 words, what steps can one take to avoid losing work? Which command is used to save changes to the database? What is the syntax for this command? Phase-2 In 100 words, explain the ...

Assignment -scenario setup a mock phase 3 clinical trial

Assignment - Scenario: Setup a Mock Phase 3 Clinical Trial for evaluating the efficacy of a Blood Pressure/Weight Loss/ or Muscle Strength Enhancement supplement. Assume that the testing takes place at a physician's offi ...

Backgrounda new training organization called abc

Background A new training organization called ABC TechTraining is opening soon and they have approached you to help design their new database. They have just completed the refurbishment of the premises and are now lookin ...

Sqlwrite a select statement that returns one column from

SQL Write a SELECT statement that returns one column from the Vendor table named Full Name. Create this column from the VendorContactFName and VendorContactLName columns. Format it as follows: last name, comma, first nam ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As