2778A ENU LabManual
2778A ENU LabManual
O F F I C I A L
M I C R O S O F T
L E A R N I N G
P R O D U C T
2778A
Lab Instructions and Lab Answer Keys: Writing Queries Using Microsoft SQL Server 2008 Transact-SQL
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. The names of manufacturers, products, or URLs are provided for informational purposes only and Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not responsible for the contents of any linked site or any link contained in a linked site, or any changes or updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission received from any linked site. Microsoft is providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement of Microsoft of the site or the products contained therein. 2008 Microsoft Corporation. All rights reserved. Microsoft, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are property of their respective owners.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008
Module 1
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008
Contents:
Exercise 1: Explore the Components and Execute Queries in SQL Server Management Studio Exercise 2: Start and Use sqlcmd Exercise 3: Generate a Report from a SQL Server Database using Microsoft Office Excel 2 5 6
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008 g a Q 8
Lab: U Using SQL Ser S rver Management Stu a m udio and SQLC CMD
Exercise 1: Explore th Components and Execute Queries in SQL Server he e Manageme Studio M ent
Sc cenario
Yo are the dat ou tabase adminis strator of Adve enture Works. The Human Resources depa artment requir that res yo generate se ou everal reports by using SQL S Server 2008. Y need to ge You enerate reports with a list of em mployee addre esses sorted by departments or a list of ad y s ddresses of em mployees residing in the Unit ted St tates. Th main tasks for this exercis are as follow he se ws: 1. . 2. . 3. . 4. . 5. . 6. . 7. . Launch SQL Server Management Stud L dio. Navigate th hrough the online help. Resize, hide and close Ob e, bject Explorer and Solution Explorer. n Create a ne solution and explore the solution objec in Object Explorer. ew cts Add projects to an existin solution and create queries in the projects. ng e Connect to SQL Server an execute a q nd query. Use Visual Query Builde to return row from a tabl er ws le.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008
Task 3: Resize, hide, and close Object Explorer and Solution Explorer
Resize the Contents pane. Close the Help window. Auto Hide the Solution Explorer pane. Auto Hide the Object Explorer pane.
Task 4: Create a new solution and explore the solution objects in Object Explorer
Dock the Object Explorer pane. View the AdventureWorks2008 tables. Create a new query. Dock the Solution Explorer pane. Add a new project. Name: PersonAddress
Task 5: Add projects to an existing solution and create queries in the projects
Create a new query. Enter the query window. Query: USE AdventureWorks2008
Execute the query. Notice the active database is changed from master to AdventureWorks2008. Add additional text to the query window. Query: SELECT DISTINCT CITY FROM Person.Address
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008
Execute the query. Notice the active database is changed from master to AdventureWorks2008. Add additional text to the query window. Query: SELECT Name, GroupName FROM HumanResources.Department
Execute the query. Save Department.sql. Save HumanResourcesDepartment.ssmssqlproj. Save solution as: Name: AdventureWorks2008.ssmssl.
Open the Query Designer. On the Query menu, click Design Query in Editor.
Examine the Add Table dialog box. Select all columns. Execute the query. Close SQL Server Management Studio. Results: After this exercise, you should have explored the components and executed queries in the SQL Server Management Studio.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008
Task 1: Start the sqlcmd utility and connect to a default instance of SQL Server
Open Command Prompt. Type sqlcmd. End the sqlcmd session.
Task 3: Run a Transact-SQL script file and save the output to a text file
In the Command Prompt window, type a sqlcmd command: Command: sqlcmd -S NY-SQL-01 -i E:\MOD01\Labfiles\Starter\Department.sql -o E:\MOD01\Labfiles\Solution\DeptList.txt
Close Notepad. Close Windows Explorer. Results: After this exercise, you should have started and used sqlcmd to create reports.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Instructions: Getting Started with Databases and Transact-SQL in SQL Server 2008
Exercise 3: Generate a Report from a SQL Server Database using Microsoft Office Excel
Scenario
You need to analyze the details of the newly hired employees by using a database diagram in SQL Server Management Studio. The main tasks for this exercise are as follows: 1. 2. 3. 4. Launch Excel. Create a new data connection in the workbook. Select the data to import and its format. View the report.
Save data connection file and finish. Description: AdventureWorks2008 Addresses Friendly Name: Addresses
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 2
Lab Instructions: Querying and Filtering Data
Contents:
Exercise 1: Retrieve Data by Using the SELECT Statement Exercise 2: Filter Data by Using Different Search Conditions Exercise 3: Use Functions to Work with Null Values Exercise 4: Formatting Result Sets 2 4 6 8
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 2: Gener rate a report by using the SELECT * statement with the FROM clause h O
Start SQL Server Management Studio and connect to NY-SQL-01. o uery window, c create a query that uses the AdventureWo y orks2008 database and displays all b In a new qu columns an all rows from the Person.P nd m Person table. Execute the query and br e rowse the results. u
Task 3: Gener rate a report by using the SELECT statement with the FROM clause h M
In a new qu uery window, t type and execute an SQL statement that: u a Accesses the Person.Person table in the AdventureWorks2008 database. n u
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Browse the result set in the Results pane and notice that only the specified columns appear. Results: After this exercise, you should have learned how to create a basic SELECT statement to retrieve data from a table.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Generate a report by using the SELECT statement with a COMPARISON operator
In a new query window enter and execute a SELECT statement that: Accesses the Production.Product table in the AdventureWorks2008 database. Includes the ProductNumber, Name, ListPrice, Color, Size, and Weight columns. The ListPrice must be lower than $100.
Task 2: Generate a report by using the SELECT statement with the AND and LIKE operators
Change the SELECT statement so that it: Accesses information in the Production.Product table of the AdventureWorks2008 database. Includes ProductNumber, Name, ListPrice, Color, Size, and Weight The ListPrice is less than $100 The ProductNumber column begins with the string SO.
Browse the result set and notice that all of the rows returned contain the word "SO".
Task 3: Generate a report by using the SELECT statement with the OR operator
Change the query to include rows with the TG as well as SO in the Name column. Execute the query. Browse the result set and note the additional rows for tights.
Task 4: Generate a report by using the SELECT statement with the BETWEEN operator
Change the query to select rows that: Display rows with SO included in the Product Number. Or rows of tights that have a list price between $50 and $180.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Browse the result set and note that the number of rows has changed and the column data matches the new search conditions.
Task 5: Generate a report by using the SELECT statement with the IN operator
Add a search condition that limits 'tights' to sizes 'M' and 'L'. Execute the query. Note the additional filtering of the data rows within the result set. Results: After this exercise, you should have learned how to use several different comparison operators to create reports specific to different user needs.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Generate a report by using the SELECT statement with the NULL function
In a new query window, enter and execute a SELECT statement that: Retrieves rows from the Production.Product table in the AdventureWorks2008 database. Includes ProductNumber, Name, and Weight. Uses the = operator to check ProductLine for a NULL value.
Browse the result set and note the total number of rows.
Task 2: Generate a report by using the SELECT statement with the IS NULL function
Change the statement to use IS NULL to select rows with a value of NULL in the ProductLine column. Execute the query. Browse the result set and notice the number of rows returned and the data displayed in the ProductLine column.
Task 3: Generate a report by using the SELECT statement with the ISNULL function to rename values
In a new query window, enter and execute a SELECT statement that: Accesses the Production.Product table in the AdventureWorks2008 database. Displays the ProductNumber, Name, Weight, and ProductLine columns. Use the ISNULL() function to display 'NA' when a NULL value is encountered in the ProductLine column.
Browse the result set and note the additional column and values. Also make note of the column headings.
Task 4: Generate a report by using the SELECT statement with the ISNULL function and a column alias
Change the statement to add "Product Line" as a column heading for the ProductLine column. Execute the query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Note that the result set is identical but with a column heading over the new column.
Task 5: Generate a report by using the SELECT statement with the ISNULL function and the COALESCE and CONVERT functions
Rewrite the statement to use the COALESCE() function to create a new column named Measurement so that: If the Weight column has a value it is shown in the Measurement column. If the Weight column is NULL but the Size column is not NULL, display the value in the Measurement column. If both columns have NULL values display 'NA'.
Execute the query. Browse the result set and notice the new values in the 'Measurement' column. Results: After this exercise, you should have learned to handle NULL values in a result set by identifying them and replacing them with alternate values when necessary.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
In this exercise, you will learn how to format result sets to make them easier to read and interpret. The main tasks for this exercise are as follows: 1. 2. 3. 4. 5. 6. Format a result set by using the ORDER BY clause. Format a result set by using the ORDER BY clause and the DESC keyword. Format a result set by using the ORDER BY clause and the DISTINCT keyword. Format a result set by concatenating strings. Format a result set by concatenating strings and using column aliasing. Format a result set by using the SUBSTRING function.
Task 2: Format a result set by using the ORDER BY clause and the DESC keyword
Rewrite the SELECT statement to: Add the ListPrice column. Sort the data by Class. Sort by ListPrice in descending order within each class.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Execute the query. Browse the result set and notice the new column has no meaningful heading.
Task 5: Format a result set by concatenating strings and using column aliasing
Rewrite the query to assign the column name 'Contacts'. Execute the query. Note the new column name in the result set.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 3
Lab Instructions: Grouping and Summarizing Data
Contents:
Exercise 1: Summarizing Data by Using Aggregate Functions Exercise 2: Summarizing Grouped Data Exercise 3: Ranking Grouped Data Exercise 4: Creating Crosstab Queries 2 5 9 11
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Start the 2778A-NY-SQL-01 virtual machine, log on as Administrator, and launch SQL Server Management Studio
Start 6235A-NY-SQL-01, and log on as Administrator with the password of Pa$$w0rd. Launch SQL Server Management Studio.
Task 2: Create and execute a query that displays a single summary value for all the rows
Create a query that will return the average vacation hours and the total sick leave hours for Vice Presidents. Use the AVG and SUM aggregate functions. Execute the query and review the results.
Task 3: Create and execute a second query that displays a single summary value for all the rows
Create a query that returns a count of employees. Use the COUNT function. Execute the query and review the results.
Task 4: Create and execute a third query that computes the total number of employees with the Addressline2 value as NULL
Create a query that returns a count of employees where the AddressLine2 column has NULL values. Use the COUNT and ISNULL functions. Execute the query and review the results.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Execute the query and review the results. Results: After this exercise, you should have launched SQL Server Management Studio and created queries to display summary values for rows. You should have also created queries to compute totals and eliminate NULL values.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Create and execute a query that computes the average number of days to manufacture a product
Create a query that returns the product ID and average days to manufacture from the Products table. Use AVG. Execute the query and review the results.
Task 2: Create and execute a query that displays the various colors of a particular product and computes the average ListPrice of the colors
Create a query that returns the color and average ListPrice for a specific product. Use a GROUP BY to ensure the averages are computed for the correct column. Use a WHERE clause to restrict the query to a single product number. Execute the query and review the results.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 3: Create and execute a query to generate a report that lists the average order quantity and sum of line total for each product with a line total that exceeds $1000000.00, and with average quantity less than 3
Create a query that returns the ProductID, average OrderQty and total of LineTotal. Use a GROUP BY to ensure the averages are computed for the correct column. Use a HAVING clause to restrict the query to run for cases where the total and averages of LineTotal and OrderQty respectively are in the proper ranges. Dont be afraid to use functions in the HAVING clause.
Task 4: Create and execute a query to group the products and then compute the sum of the quantity shelf-wise
Create a query that returns the ProductID Shelf and total Quantity for a group of products. Use a GROUP BY with the ROLLUP operator to calculate the columns in a specific order. Execute the query and review the results.
Task 6: Distinguish the rows generated by the summary or aggregations and actual table rows
Create a query that summarizes sales quotas and total YTD sales from the SalesPerson table using the CUBE operator. Use the GROUPING operator in tandem with the CUBE operator to indicate the column not being aggregated. Sum the SalesYTD column. Execute the query and review the results.
Task 7: Create and execute a query to generate a report of the summary columns by using the GROUPING function
Create a query that summarizes information about the ProductInventory table using the CUBE operator and GROUPING operator. The CUBE operator should be used with multiple columns and the GROUPING should be used with one of those columns. Sum the Quantity column. Execute the query and review the results.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 8: Create and execute a query to generate a report that displays all the products, the unit price, the unit price discount, and the sum of the columns
Create a query to summarize information about the SalesOrderDetail table using the COMPUTE clause. Sum the UnitPrice and UnitPriceDiscount columns without using aggregate functions and GROUP BY - use the COMPUTE clause. Execute the query and review the results. Results: After this exercise, you have learned how to create queries to compute averages, display additional data and perform summations. You should have also learned how to create queries using aggregation functions and the GROUPING function.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Generate row numbers for each of the rows in the year-to-date sales of the salespersons
Create a query that returns numbered rows for the SalesPerson table. Use the ROW_NUMBER function, specifying the ordering. Filter the results to prune away sales persons with null territories and no sales. Execute the query and review the results.
Task 2: Create and execute a second query using the RANK function
Create a query that returns numbered rows for the ProductInventory table. Use the RANK function, specifying the ordering. Execute the query and review the results.
Task 3: Create and execute a third query using the DENSE_RANK function
Create a query that returns numbered rows for the ProductInventory table. Use the DENSE_RANK function, specifying the ordering. Execute the query and review the results.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
10
Task 4: Create and execute a fourth query that sorts data in descending order and groups data into categories
Create a query that returns numbered rows for the SalesPerson table. Use the NTILE function, using the SalesYTD column for the ordering. Filter the results to prune away sales persons with null territories and no sales. Execute the query and review the results.
Results: After this exercise, you have learned how to create queries that use the various ranking functions to organize and rank grouped data.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
11
Task 1: Create and execute a query using SELECT and the PIVOT operator
Create a query that returns a pivoted table expression from the Product table. Use the PIVOT operator. Filter the input to only use "helmet" products. Sum the amount of each helmet by the colors of Red, Blue and Black. Order the output by product name. Execute the query and review the results.
Task 2: Create and execute a second query using SELECT and the UNPIVOT operator
Create a query that uses the UNPIVOT operator to turn a table expression into column values. Execute the query and review the results.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
12
Results: After this exercise, you have learned how to use the PIVOT operator to create a crosstab query and also how to use the UNPIVOT operator.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
13
Lab Shutdown
After you complete the lab, you must shut down the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 4
Lab Instructions: Joining Data from Multiple Tables
Contents:
Exercise 1: Querying Multiple Tables by Using Joins Exercise 2: Applying Joins for Typical Reporting Needs Exercise 3: Combining and Limiting Result Sets 2 4 5
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
he se w Th main tasks for this exercis are as follows: 1. . 2. . 3. . Launch SQL Server Management Studio. L o Create and execute an Inner Join. Create and execute a Left Outer Join and a Right Outer Join. t n t
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 3: Create and execute a Left Outer Join and a Right Outer Join
Create a Left Outer Join that uses the Product and ProductReview tables on their ProductID columns to show only those products for which reviews have been written. Create a Right Outer Join that uses the SalesTerritory and SalesPerson tables on their TerritoryID columns to show any territory that has been assigned to a salesperson. Execute the query and review the results. Results: After this exercise, you should have launched SQL Server Management Studio and created and executed an Inner Join. You should have also created and executed a Left Outer Join and a Right Outer Join.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. 3. Create and execute a query using a Self Join. Create and execute a query using a Self Join and the DISTINCT clause. Create and execute a Non-Equi Join with an equality and a non-equality operator.
Task 2: Create and execute a query using a Self Join and the DISTINCT clause
Create a query that will return a list of all products on the Purchasing.ProductVendor table that are produced by vendors. Use a Self Join that uses the DISTINCT clause, and order the results by ProductID. Execute the query and review the results.
Task 3: Create and execute a Non-Equi Join with an equality and a non-equality operator
Create a query that will return a list of all product subcategories that have at least two different prices less than $15. Use an Inner Join to join the Production.Product table to itself and a non-equality operator on the ListPrice column to select two different prices. Execute the query and review the results. Results: After this exercise, you should have created and executed a query using a self join, created and executed a query using a self join and the DISTINCT clause, and created and executed a non-equi join with both an equality and non-equality operator.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. 3. 4. Combine the result sets of two queries by using the UNION ALL operator. Limit result sets by using the EXCEPT clause with the SELECT statement. Limit result sets by using the INTERSECT clause with the SELECT statement. Limit result sets by using the TOP and TABLESAMPLE operators.
Task 1: Combine the result sets of two queries by using the UNION ALL operator
Create a query that will return a combined list of all columns on the TestA and TestB tables. Do not limit the results of the query with any operators. Execute the query and review the results.
Task 2: Limit result sets by using the EXCEPT clause with the SELECT statement
Create a query using EXCEPT that lists all product IDs from the Production.Product table that are not on the Production.WorkOrder table. Execute the query and review the results.
Task 3: Limit result sets by using the INTERSECT clause with the SELECT statement
Create a query using INTERSECT that lists all product IDs from the Production.Product table that are not on the Production.WorkOrder table. Execute the query and review the results.
Task 4: Limit result sets by using the TOP and TABLESAMPLE operators
Create a query that lists of the top 15% of products from the Production.Product table, ordered by ProductID. Execute the query and review the results. Create a query that randomly generates a list of 10% of people from the Person.Person table including first name and surname. Execute the query and review the results. Results: After this exercise, you should have combined the result sets of two queries by using the UNION ALL operator. You should have also limited result sets by using the EXCEPT and INTERSECT clauses. Finally, you should have limited result sets using the TOP and TABLESAMPLE operators.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Shutdown
After you complete the lab, you must shut down the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 5
Lab Instructions: Working with Subqueries
Contents:
Exercise 1: Writing Basic Subqueries Exercise 2: Writing Correlated Subqueries Exercise 3: Comparing Subqueries with Joins and Temporary Tables Exercise 4: Using Common Table Expressions 2 4 5 6
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
he s w Th main tasks for this exercise are as follows: 1. . 2. . 3. . Launch SQL Server Management Studio. L d Create a Ba Subquery. asic Create a Su ubquery with the EXISTS Keyword. y
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Execute the query and review the results. Results: After this exercise, you should have launched SQL Server Management Studio and created and executed a basic subquery. You should have also created and executed a subquery with the EXISTS keyword.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. Create a Correlated Subquery. Create a Correlated Subquery with Comparison Operators.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. Create a Subquery and a Join that Produce the same Result Set. Create a Temporary Table.
Task 1: Create a subquery and a join that produce the same result set
Create a subquery to select the name of any products that have a list price equal to the list price of 'Chainring Bolts' on the Production.Product table. Create and execute a join to select the name of any products that have a list price equal to the list price of 'Chainring Bolts' on the Production.Product table.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. Create a Common Table Expression. Create a Recursive Query using a Common Table Expression.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Shutdown
After you complete the lab, you must shut down the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 6
Lab Instructions: Modifying Data in Tables
Contents:
Exercise 1: Inserting Data into Tables Exercise 2: Deleting Data from Tables Exercise 3: Updating Data in Tables Exercise 4: Working with Transactions 3 5 6 7
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Include information about new departments and their managers: PhoneNumberTypeI BusinessEntityID PhoneNumber D ModifiedDate 1705 1706 864-555-2101 712-555-0118 3 1 GETDATE() GETDATE()
Include information about a faulty product: Name Operator error ModifiedDate GETDATE()
The main tasks for this exercise are as follows: 1. 2. 3. 4. Launch SQL Server Management Studio. Create an INSERT Statement that Adds Values to a Table. Create an INSERT Statement Using the INTO Syntax. Create an INSERT Statement Using the OUTPUT Syntax.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Insert the ScrapreasonID, Name, and ModifiedDate columns and rows from the Production.ScrapReason table into @MyTableVar using the INSERT and OUTPUT statements. Display the result set of the table variable and display the result set of the table. Results: After this exercise, you should have launched SQL Server Management Studio, created and executed an INSERT statement that adds values to a table, created and executed an INSERT statement using the INTO syntax, and created and executed an INSERT statement using the OUTPUT syntax.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The director of sales has now asked you to make the following updates to the database: Remove rows from the sales person quota history based on the year-to-date sales stored in the SalesPerson table, where year-to-date sales are greater-than $1,000,000.00. Delete the Sales.ShoppingCartItem table and display the results of the deletion. Truncate the Production.TransactionHistory table and display the results.
The main tasks for this exercise are as follows: 1. 2. 3. 4. Create a DELETE Statement Using the WHERE Syntax. Create a DELETE Statement Using the FROM Syntax. Create a DELETE Statement Using the OUTPUT Syntax. Create a TRUNCATE TABLE Statement.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. 3. 4. Create an UPDATE Statement Using the SET Syntax. Create an UPDATE Statement Using the WHERE Syntax. Create an UPDATE Statement Using the FROM Syntax. Create an UPDATE Statement Using the OUTPUT Syntax.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
The main tasks for this exercise are as follows: 1. 2. Create a Simple Transaction. Set a Transaction Isolation Level.
Lab Shutdown
After you complete the lab, you must shut down the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 7
Lab Instructions: Querying Metadata, XML, and Full-Text Indexes
Contents:
Exercise 1: Querying Metadata Exercise 2: Querying XML Data Exercise 3: Creating and Querying Full-Text Indexes 2 4 5
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Shutdown
After you complete the lab, you must shut down the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 8
Lab Instructions: Using Programming Objects for Data Retrieval
Contents:
Exercise 1: Creating Views Exercise 2: Creating User-Defined Functions Exercise 3: Creating Stored Procedures Exercise 4: Writing Distributed Queries 2 3 4 5
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Create a view to s e select only t name an ID columns from the Person tabl the nd le
In SQL Serv Managem ver ment Studio, c create a new vi iew. In the view, select BusinessEntityID, Firs , stName, MiddleName, and L LastName from the m Person.Person table. ry Create the view and quer it. Results: After this exercise, y should ha created a v you ave view and queried it using a T T-SQL query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Create a stored procedure to select the name columns from the Person table for a given ID
In SQL Server Management Studio, create a new stored procedure. Accept an integer PersonID value as an input parameter. In the stored procedure, select FirstName, MiddleName, and LastName from the view created in Exercise 2. Create the stored procedure. Results: After this exercise, you should have created a stored procedure that queries a view.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 2: Executing an ad hoc distributed query against a Microsoft Office Excel spreadsheet
Create a query that uses the OPENROWSET function with the following parameters:
'Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=E:\Mod08\Labfiles\SalesSummary2008.xls', 'SELECT Country, TotalSales FROM [Sheet1$]'
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Shutdown
After you complete the lab, you must shut down the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 9
Lab Instructions: Using Advanced Techniques
Contents:
Exercise 1: Using Execution Plans Exercise 2: Converting Data Types Exercise 3: Implementing a Hierarchy Exercise 4: Using Cursors and Set-Based Queries 2 4 6 7
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 1: Start the 2778A-N t NY-SQL-01 virtual machine and log on as Administrator h g
Start NY-SQ QL-01 and log on as Administrator with a password of Pa$$w0rd. g n f
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Review the Results pane. SQL Server automatically converted "False" to a data type of bit to compare it to the SalariedFlag column. Look up the data types for the ListPrice and StandardCost columns in the Production.Product table. Create a new query on the AdventureWorks2008 database with the following code:
DECLARE @NewListPrice nvarchar(10) = '39.99' DECLARE @NewStandardCost float = 12.45 UPDATE Production.Product SET ListPrice = @NewListPrice, StandardCost = @NewStandardCost WHERE ProductID = '2'
Run the query. Create a new query on the AdventureWorks2008 database with the following code:
SELECT Name, StandardCost, ListPrice from Production.Product WHERE ProductID = '2'
Run the query. In the results pane, notice that the ListPrice and StandardCost columns have been updated. SQL Server automatically converted the nvarchar and float types in the update query to the money data type used by the columns. Open the file E:\Mod09\Labfiles\Starter\Exercise02\UpdateDemographics.sql. Notice that the variable @NewDemographics is an nvarchar data type and contains a valid XML string. Run the query. Create a new query on the AdventureWorks2008 database with the following code:
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Run the query. In the Results pane, click the link in the Demographics column. SQL Server converted the nvarchar string to the xml data type automatically because the XML was valid.
Run the query. In the Results pane, there is a single column with the employee name and pay rate combined. Open the file E:\Mod09\Labfiles\Starter\Exercise02\PayRateLastChange.sql. Run the query. Review the results of the query. Notice that the last column does not show both the pay rate and date. In the query pane, modify the SELECT statement so that it begins as follows:
SELECT p.FirstName, p.LastName, (CAST(s.Rate AS nvarchar) + ' ' + s.RateChangeDate)
Run the query, and take note of the error message. Modify the SELECT statement again, so that it reads as follows:
SELECT p.FirstName, p.LastName, (CAST(s.Rate AS nvarchar) + ' ' + CAST(s.RateChangeDate as nvarchar))
Run the query. Notice that the query now runs and the last column displays the correct information. Results: After this exercise, you should have verified that SQL Server automatically performs implicit conversions, and you should have also successfully run queries that performed explicit data type conversions.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Review the StandardCost and ListPrice columns in the Results pane. Keep this query pane open. Open the E:\Mod09\Labfiles\Starter\Exercise04\UpdateListPriceCursor.sql file. Review and execute the query. When the update is complete, run the SELECT query again. Review the ListPrice column in the Results pane. The ListPrice column has been updated.
Run the query. When the update is complete, run the SELECT query again. Review the StandardCost column in the Results pane. The StandardCost column has been updated. Close SQL Server Management Studio without saving changes. Turn off the virtual machine and discard changes. Results: After this exercise, you should have used a cursor to update the ListPrice column and used a set-based query to update the StandardCost column of the Production.Product table.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
Module 1
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
Contents:
Exercise 1: Explore the Components and Execute Queries in SQL Server Management Studio Exercise 2: Start and Use sqlcmd Exercise 3: Generate a Report from a SQL Server Database using Microsoft Office Excel 2 5 6
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
4. 5. 6.
Task 3: Resize, hide, and close Object Explorer and Solution Explorer
1. 2. 3. 4. 5. 6. Reduce the size of the Contents pane by resizing it. Scroll down the Connecting with Registered Servers and Object Explorer page to view its contents. Click the Close button to close the Help window. On the View menu, click Solution Explorer. In Solution Explorer, click Auto Hide to hide the pane. In Object Explorer, click Auto Hide to hide the pane.
Task 4: Create a new solution and explore the solution objects in Object Explorer
1. 2. 3. 4. 5. 6. 7. Open Object Explorer by clicking the Object Explorer tab. In Object Explorer, click Auto Hide to dock the pane. In the Object Explorer, double-click the Databases folder, double-click AdventureWorks2008, and then double-click Tables. You can scroll through the pane to view the list of tables. On the toolbar, click New Query. The SQLQuery1.sql - NY-SQL-01.AdventureWorks2008 window opens. Open Solution Explorer by clicking the Solution Explorer tab. In Solution Explorer, click Auto Hide to dock the pane.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
In Solution Explorer, right-click Solution 'Solution1' (1 project), point to Add, and then click New Project. The Add New Project dialog box appears. In the Templates box, verify that the SQL Server Scripts template is highlighted. In the Name field, select SQL Server Scripts1, type PersonAddress, and then click OK. The PersonAddress project will be created under Solution Solution1 (1 project). In Solution Explorer, in the PersonAddress project, right-click Connections, and then click New Connection. The Connect to Server dialog box appears. Verify the connection information, and then click OK.
Task 5: Add projects to an existing solution and create queries in the projects
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. In the Connections folder of the PersonAddress project, right-click NY-SQL-01:NY-SQL-01\Student, and then click New Query. The SQLQuery1.sql object appears in the Queries folder. In the query window, type USE AdventureWorks2008, and then press ENTER. On the toolbar, click Execute. The active database is changed to AdventureWorks2008. In the query window, type SELECT DISTINCT CITY FROM Person.Address. On the toolbar, click Execute. The list of cities in the Person.Address table is displayed without repetition in the Results pane. In the Queries folder of PersonAddress project, right-click SQLQuery1.sql, and then click Rename. Rename the query as Address.sql. The query has been renamed to Address.sql. On the File menu, click Save Address.sql. In Solution Explorer, right-click PersonAddress, and then click Save PersonAddress.ssmssqlproj. Right-click Solution Solution1 (1 project), point to Add, and then click New Project. The Add New Project dialog box appears. In the Templates box, verify that the SQL Server Scripts template is highlighted. In the Name field, select SQL Server Scripts1, type HumanResourcesDepartment, and then click OK. The HumanResourcesDepartment project is created under Solution Solution1 (2 projects). In the HumanResourceDepartments project, right-click Connections, and then click New Connection. The Connect to Server dialog box appears. Verify the connection information, and then click OK. In the Connections folder, under HumanResourceDepartments, right-click NY-SQL-01:NY-SQL01\Student and then click New Query. The SQLQuery1.sql folder appears. In the Queries folder of HumanResourcesDepartment project, right-click SQLQuery1.sql, and then click Rename. Rename the query as Department.sql. The query has been renamed to Department.sql. In the query window, type USE AdventureWorks2008, and then press ENTER. On the toolbar, click Execute. The active database is changed to AdventureWorks2008. In the query window, type SELECT Name, GroupName FROM HumanResources.Department. On the toolbar, click Execute. The Name and GroupName columns are displayed in the Results pane. On the File menu, and click Save Department.sql.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
34. In Solution Explorer, right-click the HumanResourcesDepartment project, and then click Save HumanResourcesDepartment.ssmssqlproj. 35. Click Solution Solution1 (2 projects). 36. On the File menu, click Save Solution1 As. 37. The Save File As dialog box appears. Verify that the Projects folder is selected in the Save in: list. 38. In the File name field, type AdventureWorks2008.ssmssln, and then click Save. 39. Click the Close button to close SQL Server Management Studio.
Results: After this exercise, you should have explored the components and executed queries in the SQL Server Management Studio.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
5.
Task 3: Run a Transact-SQL script file and save the output to a text file
1. 2. 3. In the Command Prompt window, type: sqlcmd -S NY-SQL-01 -i E:\MOD01\Labfiles\Starter\Department.sql -o E:\MOD01\Labfiles\Solution\DeptList.txt. Press ENTER. Notice that there is no output in the Command Prompt window.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Lab Answer Keys: Getting Started with Databases and Transact-SQL in SQL Server 2008
Exercise 3: Generate a report from a SQL Server database using Microsoft Office Excel
Task 1: Launch Excel
1. 2. On the Start menu, click All Programs, click Microsoft Office, and then click Microsoft Office Excel 2007. The Microsoft Excel window opens.
Results: After this exercise, you should create a report from a SQL Server database using Microsoft Office Excel.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 2
Lab Answer Keys: Querying and Filtering Data
Contents:
Exercise 1: Exploring SQL Server Management Studio Exercise 2: Filter Data by Using Various Search Conditions Exercise 3: Using Functions to Work with Null Values Exercise 4: Formatting Result Sets 2 2 5 6
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 2: Generate a report by using the SELECT * statement with the FROM clause
1. 2. On the Start menu, point to All Programs, click Microsoft SQL Server 2008 and click SQL Server Management Studio. In the Connect to Server dialog box, verify that the Server type, Server name, and the Authentication boxes have been populated correctly, and click Connect to accept the default settings. On the toolbar of SQL Server Management Studio, click New Query. A new query opens in the query window. In the query window type the following SQL Statement:
USE AdventureWorks2008 GO SELECT * FROM Person.Person
3. 4.
5. 6.
Task 3: Generate a report by using the SELECT statement with the FROM clause
1. 2. On the toolbar of SQL Server Management Studio, click New Query. A new query opens in the query window. In the new query window type and execute the following SQL statement:
USE AdventureWorks2008 GO SELECT Title, FirstName, LastName, MiddleName FROM Person.Person
3. 4.
Click Execute. The result set is displayed in the Results pane. Browse the result set in the Results pane and notice that only the specified columns appear.
Results: After this exercise, you should have learned how to create a basic SELECT statement to retrieve data from a table.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3.
Task 2: Generate a report by using the SELECT statement with the AND and LIKE operators
1. Enter the following SQL Statement in the Query window:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, ListPrice, Color, Size, Weight FROM Production.Product WHERE ListPrice < $100 AND ProductNumber LIKE 'SO%'
2.
Task 3: Generate a report by using the SELECT statement with the OR operator
1. Change the SQL statement to read:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, ListPrice, Color, Size, Weight FROM Production.Product WHERE ListPrice < $100 AND ProductNumber Like 'SO%' OR ProductNumber Like 'TG%'
2.
Task 4: Generate a report by using the SELECT statement with the BETWEEN operator
1. Click New Query and type the following SQL statement into the Query window:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, ListPrice, Color, Size, Weight FROM Production.Product WHERE ProductNumber LIKE 'SO%' OR (ListPrice Between $50 and $180 AND ProductNumber LIKE 'TG%')
2.
Task 5: Generate a report by using the SELECT statement with the IN operator
1. Rewrite the SQL statement to read as follows:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, ListPrice, Color, Size, Weight FROM Production.Product WHERE ProductNumber LIKE 'SO%' OR (ListPrice Between $50 and $180 AND ProductNumber LIKE 'TG%' AND Size IN ('M', 'L'))
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
2.
Results: After this exercise, you should have learned how to use several different comparison operators to create reports specific to different user needs.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
Click Execute. Notice that no result set is displayed in the Results pane.
Task 2: Generate a report by using the SELECT statement with the IS NULL function
1. Rewrite the SQL statement to use IS NULL:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, Weight FROM Production.Product WHERE ProductLine IS NULL
2. 3.
Click Execute. Browse the result set displayed in the Results pane.
Task 3: Generate a report by using the SELECT statement with the ISNULL function to rename values
1. 2. On the toolbar of SQL Server Management Studio, click New Query. A new query opens in the query window. In the query window type the following SQL statement:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, Weight, ISNULL(ProductLine, 'NA') FROM Production.Product
3. 4.
Click Execute. The result set is displayed in the Results pane. Notice that the new column shows NA in all rows that Weight has a NULL value. But the column has no heading.
Task 4: Generate a report by using the SELECT statement with the ISNULL function and a column alias
1. Change the statement as follows, to add Product Line as a column heading for the ProductLine column:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, Weight, ISNULL(ProductLine, 'NA') AS Product Line
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
FROM Production.Product
2. 3.
Click Execute. The result set is displayed in the Results pane. Note that the new column now has the heading of Product Line.
Task 5: Generate a report by using the SELECT statement with the ISNULL function and the COALESCE and CONVERT functions
1. Click New Query and enter the following SQL Statement into the Query window:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, COALESCE(CONVERT(NVARCHAR,Weight), SIZE, 'NA') AS Measurement, ISNULL(ProductLine, 'NA') AS Product Line FROM Production.Product
2. 3.
Click Execute. The result set is displayed in the Results pane. Notice the values in the Measurement column.
Results: After this exercise, you should have learned to handle NULL values in a result set by identifying them and replacing them with alternate values when necessary.
3.
Click Execute.
Task 2: Format a result set by using the ORDER BY clause and the DESC keyword
1. 2. Click New Query. Type the following SQL statement into the Query window:
USE AdventureWorks2008 GO SELECT ProductNumber, Name, Class, ListPrice FROM Production.Product ORDER BY Class, ListPrice Desc
3.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3.
3.
Task 5: Format a result set by concatenating strings and using column aliasing
1. Rewrite the query to assign the column name Contacts.
USE AdventureWorks2008 GO SELECT (LastName + ',' + FirstName) AS Contacts FROM Person.Person
2.
2. 3. 4.
Click Execute. The result set is displayed in the Results pane. On the File menu, click Exit and answer No to the save queries prompt. Turn off NY-SQL-01 and discard changes.
Results: After this exercise, you should have learned how to format the result sets to make them more readable.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 3
Lab Answer Keys: Grouping and Summarizing Data
Contents:
Exercise 1: Summarizing Data by Using Aggregate Functions Exercise 2: Summarizing Grouped Data Exercise 3: Ranking Grouped Data Exercise 4: Creating Crosstab Queries 2 4 6 7
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 2: Write a query that displays a single summary value for all the rows
1. 2. 3. On the toolbar of SQL Server Management Studio, click New Query. A new query opens in the query window. In the Available Databases list on the toolbar, click AdventureWorks2008. You are connected to the AdventureWorks2008 database. In the query window, type the following SQL statements:
SELECT AVG(VacationHours) AS 'AverageVacationHours', SUM(SickLeaveHours) AS 'TotalSickLeave Hours' FROM HumanResources.Employee WHERE JobTitle LIKE '%Vice President%'
4.
Task 3: Write a second query that displays a single summary value for all rows
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statement:
SELECT COUNT(*) FROM HumanResources.Employee
3.
Task 4: Write a query that computes the total number of employees with the AddressLine2 value as NULL
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statement:
SELECT COUNT(*) FROM Person.Address WHERE ISNULL (AddressLine2, '0') = '0'
3.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4. 5.
Select the query, and on the toolbar, click Execute. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the SQL statement:
SELECT COUNT (DISTINCT AddressLine2) FROM Person.Address
6.
Results: After this exercise you should have launched SQL Server Management Studio and created queries to display summary values for rows. You should have also created queries to compute totals and eliminate NULL values.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
4.
Task 2: Write a query that displays the various colors of a particular product and the average ListPrice of the colors
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT Color, AVG(ListPrice) AS 'AvgListPrice' FROM Production.Product WHERE ProductNumber = 'FR-R72R-58' GROUP BY ALL Color
3.
Task 3: Generate a report that lists the average order quantity and sum of line total for each product with a line total that exceeds $1000000.00 and with average quantity less than 3
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT ProductID, AVG(OrderQty) AS 'AverageQuantity', SUM(LineTotal) AS Total FROM Sales.SalesOrderDetail GROUP BY ProductID HAVING SUM(LineTotal) > $1000000.00 AND AVG(OrderQty) < 3
3.
Task 4: Group the products and then compute the sum of the quantity shelf-wise
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT ProductID, Shelf, SUM(Quantity) AS 'QtySum' FROM Production.ProductInventory GROUP BY ROLLUP(ProductID, Shelf)
3.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3.
Task 6: Distinguish the rows generated by the summary or aggregations and actual table rows
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT SalesQuota, SUM(SalesYTD) 'TotalSalesYTD', GROUPING(SalesQuota) AS 'Grouping' FROM sales.SalesPerson GROUP BY CUBE(SalesQuota)
3.
Task 7: Generate a report of the summary columns by using the GROUPING function
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT ProductID, Shelf, SUM(Quantity) AS 'TotalQuantity', GROUPING (Shelf) AS 'Shelfgrouping' FROM Production.ProductInventory GROUP BY CUBE(ProductID, Shelf)
3.
Task 8: Generate a report that displays all the products, the unit price, the unit price discount, and the sum of the columns
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT SalesOrderID, UnitPrice, UnitPriceDiscount FROM Sales.SalesOrderDetail ORDER BY SalesOrderID COMPUTE SUM(UnitPrice), SUM(UnitPriceDiscount)
3.
Results: After this exercise you have learned how to create queries to compute averages, display additional data and perform summations. You should have also learned how to create queries using aggregation functions and the GROUPING function.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
4.
Task 2: Generate a report that ranks the products by using the RANK function
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT RANK() OVER (PARTITION BY LocationID ORDER BY Quantity DESC) AS RANK, ProductID, LocationID, Quantity FROM Production.ProductInventory ORDER BY RANK
3.
Task 3: Generate a report that ranks the products by using the DENSE_RANK function
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT DENSE_RANK() OVER (PARTITION BY LocationID ORDER BY Quantity ProductID, LocationID, Quantity FROM Production.ProductInventory ORDER BY RANK DESC) AS RANK,
3.
Task 4: Generate a report that lists the details of salespersons based on their year-todate sales in descending order, and then group them into four categories
1. 2. On the toolbar of SQL Server Management Studio, click New Query. In the query window, type the following SQL statements:
SELECT NTILE(4) OVER(ORDER BY SalesYTD DESC) AS 'Quartile',SalesYTD, BusinessEntityID FROM Sales.SalesPerson WHERE TerritoryID IS NOT NULL AND SalesYTD <> 0
3.
Results: After this exercise you have learned how to create queries that use the various ranking functions to organize and rank grouped data.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
4.
3. 4.
Select the statement, and on the toolbar click Execute. Turn off the 2778A-NY-SQL-01 virtual machine and discard any changes.
Results: After this exercise you have learned how to use the PIVOT operator to create a crosstab query and also how to use the UNPIVOT operator.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 4
Lab Answer Keys: Joining Data from Multiple Tables
Contents:
Exercise 1: Querying Multiple Tables by Using Joins Exercise 2: Applying Joins for Typical Reporting Needs Exercise 3: Combining and Limiting Result Sets 2 4 5
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 3: Create and execute a left outer join and a right outer join
1. 2. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT p.Name, pr.ProductReviewID FROM Production.Product p LEFT OUTER JOIN Production.ProductReview pr ON p.ProductID = pr.ProductID;
3. 4. 5. 6.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT st.Name AS Territory, sp.BusinessEntityID FROM Sales.SalesTerritory st RIGHT OUTER JOIN Sales.SalesPerson sp ON st.TerritoryID = sp.TerritoryID;
7. 8.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
9.
Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise, you should have launched SQL Server Management Studio and created and executed an Inner Join. You should have also created and executed a Left Outer Join and a Right Outer Join.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 2: Create and execute a query using a self join and the DISTINCT clause
1. 2. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT DISTINCT pv1.ProductID, pv1.BusinessEntityID FROM Purchasing.ProductVendor pv1 INNER JOIN Purchasing.ProductVendor pv2 ON pv1.ProductID = pv2.ProductID AND pv1.BusinessEntityID <> pv2.BusinessEntityID ORDER BY pv1.ProductID;
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 3: Create and execute a non-equi join with an equality and a non-equality operator
1. 2. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT DISTINCT p1.ProductSubcategoryID, p1.ListPrice FROM Production.Product p1 INNER JOIN Production.Product p2 ON p1.ProductSubcategoryID = p2.ProductSubcategoryID AND p1.ListPrice <> p2.ListPrice WHERE p1.ListPrice < $15 AND p2.ListPrice < $15 ORDER BY ProductSubcategoryID;
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise, you should have created and executed a query using a self join, created and executed a query using a self join and the DISTINCT clause, and created and executed a non-equi join with both an equality and non-equality operator.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 2: Limit result sets by using the EXCEPT clause with the SELECT statement
1. 2. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT ProductID FROM Production.Product EXCEPT SELECT ProductID FROM Production.WorkOrder;
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 3: Limit result sets by using the INTERSECT clause with the SELECT statement
1. 2. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT ProductID FROM Production.Product INTERSECT SELECT ProductID FROM Production.WorkOrder;
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 4: Limit result sets by using the TOP and TABLESAMPLE operators
1. 2. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
SELECT TOP(15) PERCENT ProductID FROM Production.Product ORDER BY ProductID;
3. 4. 5. 6.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. On the toolbar, click New Query. In the new, blank query window type the following T-SQL statement:
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
7. 8. 9.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Turn off the 2778A-NY-SQL-01 virtual machine and discard any changes.
Results: After this exercise, you should have combined the result sets of two queries by using the UNION ALL operator. You should have also limited result sets by using the EXCEPT and INTERSECT clauses. Finally you should have limited result sets using the TOP and TABLESAMPLE operators.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 5
Lab Answer Keys: Working with Subqueries
Contents:
Exercise 1: Writing Basic Subqueries Exercise 2: Writing Correlated Subqueries Exercise 3: Comparing Subqueries with Joins and Temporary Tables Exercise 4: Using Common Table Expressions 2 3 4 5
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise, you should have launched SQL Server Management Studio and created and executed a basic subquery. You should have also created and executed a subquery with the EXISTS keyword.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise, you should have created a correlated subquery and also created a correlated subquery with comparison operators.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise you should have created a subquery and a join that produced the same result set. You should have also created a temporary table.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Turn off the 2778A-NY-SQL-01 virtual machine and discard any changes.
Results: After this exercise you should have created a common table expression. You should have also created a recursive query using a common table expression.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 6
Lab Answer Keys: Modifying Data in Tables
Contents:
Exercise 1: Inserting Data into Tables Exercise 2: Deleting Data from Tables Exercise 3: Updating Data in Tables Exercise 4: Working with Transactions 2 4 5 7
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise, you should have launched SQL Server Management Studio, created and executed an INSERT statement that adds values to a table, created and executed an INSERT statement using the INTO syntax, and created and executed an INSERT statement using the OUTPUT syntax.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise, you should have created and executed a DELETE statement using the WHERE syntax and created and executed a DELETE statement using the FROM syntax. You should have also created and executed a DELETE statement using the OUTPUT syntax and then created and executed a TRUNCATE TABLE statement.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Leave Microsoft SQL Server Management Studio open for the next exercise.
Results: After this exercise you should have created and executed an UPDATE statement using the SET syntax, created and executed an UPDATE statement using the WHERE IN (SELECT) syntax, and created and executed an UPDATE statement using the FROM syntax. You should have also created and executed an UPDATE statement using the OUTPUT syntax.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Turn off the 2778A-NY-SQL-01 virtual machine and discard any changes.
Results: After this exercise, you should have created a simple transaction. You should have also set the transaction isolation level for a new transaction.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 7
Lab Answer Keys: Querying Metadata, XML, and Full-Text Indexes
Contents:
Exercise 1: Querying Metadata Exercise 2: Querying XML Data Exercise 3: Creating and Querying Full-Text Indexes 2 4 5
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Results: After this exercise, you should have launched SQL Server Management Studio and queried metadata using system catalog views, the information schema, dynamic management views, and system stored procedures.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Results: After this exercise, you should have created a query of relational data and produced the output in XML format. You should have also created a query that converts data in XML format to a relational format.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Turn off 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Results: After this exercise, you should have created a new full-text Index and queried that Index using both the FREETEXT and CONTAINS predicates.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 8
Lab Answer Keys: Using Programming Objects for Data Retrieval
Contents:
Exercise 1: Creating Views Exercise 2: Creating User-Defined Functions Exercise 3: Creating Stored Procedures Exercise 4: Writing Distributed Queries 2 3 5 6
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Task 2: Create a view to select only the ID and Name columns from the Person table
1. 2. Right-click the AdventureWorks2008 database, and then click New Query. In the new, blank query window, type the following T-SQL statement:
CREATE VIEW [dbo].[vwPersonName] AS SELECT BusinessEntityID, FirstName, MiddleName, LastName FROM Person.Person GO
3. 4. 5. 6.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Right-click the AdventureWorks2008 database, and then click New Query. In the new, blank query window, type the following T-SQL statement:
SELECT * FROM vwPersonName
7. 8.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Results: After this exercise, you should have created a view to restrict the number of columns returned for a table.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4. 5. 6.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Right-click the AdventureWorks2008 database, and then click New Query. In the new, blank query window, type the following T-SQL statement:
SELECT GETDATE() SELECT dbo.fnGetDate(GETDATE())
7. 8.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4. 5. 6.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Right-click the AdventureWorks2008 database, and then click New Query. In the new, blank query window, type the following T-SQL statement:
SELECT * FROM fnGetVendorPurchaseOrders(1624)
7. 8.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Results: After this exercise, you should have launched SQL Server Management Studio and created both a scalar and table-valued user-defined function.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Results: After this exercise, you should have created a stored procedure that returns a persons name using their ID.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
Task 2: Executing an ad hoc distributed query against a Microsoft Office Excel spreadsheet
1. 2. Right-click the AdventureWorks2008 database, and then click New Query. In the new, blank query window, type the following T-SQL statement:
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=E:\Mod08\Labfiles\SalesSummary2008.xls', 'SELECT Country, TotalSales FROM [Sheet1$]')
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query.
3. 4. 5.
On the toolbar, click Execute. Review the results of the query and then close the query editor without saving the query. Turn off the 2778A-NY-SQL-01 virtual machine and discard any changes.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Results: After this exercise, you should have used an ad hoc distributed query to query data from a spreadsheet. You have also created a linked server and queried it using a four part name.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Module 9
Lab Answer Keys: Using Advanced Techniques
Contents:
Exercise 1: Using Execution Plans Exercise 2: Converting Data Types Exercise 3: Implementing a Hierarchy Exercise 4: Using Cursors and Set-Based Queries 2 3 6 7
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Results: After this exercise, you should have viewed estimated and actual execution plans for a query, and saved an execution plan to an XML file.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
5. 6. 7. 8. 9.
On the toolbar, click Execute. In the Results pane, review the result set and noticed that the values in the SalariedFlag column are 0. In Object Explorer, expand AdventureWorks2008 | Tables | Production.Product | Columns. Notice that the StandardCost and ListPrice columns have a data type of money. Right-click AdventureWorks2008, and then click New Query.
11. On the toolbar, click Execute. 12. On the toolbar, click New Query. 13. In the query pane, type the following query:
SELECT Name, StandardCost, ListPrice FROM Production.Product WHERE ProductID = '2'
14. On the toolbar click, Execute. 15. In the results pane, notice that the StandardCost and ListPrice columns have been updated. 16. On the File menu, point to Open, and then click File. 17. The Open File dialog box appears. Browse to E:\MOD09\Labfiles\Starter\Exercise02. 18. Click UpdateDemographics.sql, and then click Open. 19. In the query pane, notice that the @NewDemographics variable has a data type of nvarchar, and contains a valid XML string. 20. On the toolbar, click Execute.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
21. On the toolbar, click New Query. 22. In the query pane, type the following query:
SELECT FirstName, MiddleName, LastName, Demographics FROM Person.Person WHERE BusinessEntityID = 15
23. On the toolbar, click Execute. 24. In the Results pane, click the link in the Demographics column. 25. The Demographics.xml window opens. Notice that the string has been converted and stored as XML. 26. Close the Demographics.xml window.
7. 8. 9.
On the toolbar, click Execute. In the Results pane, notice that there is a single column of employees and pay rates combined. On the File menu, point to Open, and then click File.
10. The Open File dialog box appears. Browse to E:\MOD09\Labfiles\Starter\Exercise02. 11. Click PayRateLastChange.sql, and then click Open. 12. On the toolbar, click Execute. 13. In the Results pane, notice that the query runs successfully, but the last column does not show both the pay rate and date. 14. In the query pane, modify the line beginning with SELECT so that it reads as follows:
SELECT p.FirstName, p.LastName, (CAST(s.Rate AS nvarchar) + ' ' + s.RateChangeDate)
15. On the toolbar, click Execute. 16. In the Messages pane, take note of the error. 17. In the query pane, modify the line beginning with SELECT so that it reads as follows:
SELECT p.FirstName, p.LastName, (CAST(s.Rate AS nvarchar) + ' ' + CAST(s.RateChangeDate as nvarchar))
18. On the toolbar, click Execute. 19. In the Results pane, notice that the query now succeeds and includes the pay rate and date in the last column.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
20. Close the PayRateChange.sql file. Click No when prompted to save changes. Results: After this exercise, you should have converted several different data types to other data types using explicit and implicit conversion.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
Results: After this exercise, you should have created a hierarchy to store hierarchical data using the hierarchyid data type.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.
QuickStart Intelligence
3. 4. 5. 6. 7. 8. 9.
On the toolbar, click Execute. In the Results pane, review the ListPrice and StandardCost columns. Keep the query pane open. On the File menu, point to Open, and then click File. The Open File dialog box appears. Browse to E:\MOD09\Labfiles\Starter\Exercise04. Click UpdateListPriceCursor.sql, and then click Open. On the toolbar, click Execute. Switch back to the SELECT query above and then on the toolbar, click Execute.
10. In the Results pane, verify that the ListPrice column has been updated. Keep the query pane open.
3. 4. 5. 6. 7.
On the toolbar click Execute. Switch back to the SELECT query above, and then on the toolbar, click Execute. In the Results pane, verify that the StandardCost column has been updated. Close SQL Server Management Studio. Click No if prompted to save changes. Turn off the virtual machine and discard changes.
Results: After this exercise, you should have written a cursor to perform operations on a result set, and rewritten a cursor to use a set-based approach.
This is a unique copy of the course material identified by code cbbd3d2c-1b8b-4127-8769-5439cb34900e, and provided to you by Holly Stiver. It is illegal to reprint, redistribute, or resell this content. The Licensed Content is licensed "as-is." Microsoft does not support this Licensed Content in any way and Microsoft gives no express warranties, guarantees or conditions. Please report any unauthorized use of this content to [email protected] or by calling +1 800-785-3448.