- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Cursors in VS .NET
Cursors Print UPC Code In .NET Using Barcode printer for .NET Control to generate, create UPCA image in .NET framework applications. www.OnBarcode.comRecognize UPC-A Supplement 2 In VS .NET Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comYou should generally avoid using cursors because of their negative effect on performance. They have such an effect partly because each execution of a FETCH statement in a cursor loop is similar in performance cost to executing a SELECT statement that returns one row. Another problem is that a DML statement is optimized as a single unit, while a cursor loop cannot be optimized in the same way. Instead, each item in the loop will be optimized and executed separately for each iteration of the loop. Bar Code Generation In .NET Using Barcode drawer for VS .NET Control to generate, create barcode image in .NET applications. www.OnBarcode.comRecognizing Bar Code In .NET Framework Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.com 7
Making Universal Product Code Version A In Visual C# Using Barcode generator for Visual Studio .NET Control to generate, create UPC-A image in VS .NET applications. www.OnBarcode.comEncode UPC Symbol In .NET Framework Using Barcode drawer for ASP.NET Control to generate, create UPC Symbol image in ASP.NET applications. www.OnBarcode.comOptimizing SQL Server 2005 Performance
Encoding UPC Code In Visual Basic .NET Using Barcode maker for VS .NET Control to generate, create UPCA image in VS .NET applications. www.OnBarcode.comEAN / UCC - 13 Maker In .NET Framework Using Barcode creator for .NET framework Control to generate, create UCC - 12 image in .NET framework applications. www.OnBarcode.comYou should try to rewrite cursor logic into one or more set-based statements (SELECT, INSERT, UPDATE, DELETE). If you must use cursors, consider implementing the logic using a CLR stored procedure or a table-valued user-defined function instead (depending on the functionality you need). Draw Bar Code In VS .NET Using Barcode creation for .NET framework Control to generate, create barcode image in .NET applications. www.OnBarcode.comPrint USS Code 39 In .NET Using Barcode creation for VS .NET Control to generate, create ANSI/AIM Code 39 image in VS .NET applications. www.OnBarcode.comLab: Comparing Query Performance
Draw GS1 DataBar Stacked In .NET Framework Using Barcode generator for .NET framework Control to generate, create GS1 DataBar image in .NET framework applications. www.OnBarcode.comISBN - 10 Generation In Visual Studio .NET Using Barcode generation for VS .NET Control to generate, create International Standard Book Number image in VS .NET applications. www.OnBarcode.comIn this lab, you will test the query performance of three different queries that should produce the same result set. The query will return all customers in a specific territory and the last order received for those customers. If the customer does not have any orders, it must still be returned. The completed lab is available in the \Labs\ 07\Lab1 folder on the companion CD. Print Code 128A In Objective-C Using Barcode encoder for iPhone Control to generate, create Code 128 Code Set C image in iPhone applications. www.OnBarcode.comMatrix Barcode Creation In Visual C# Using Barcode drawer for VS .NET Control to generate, create Matrix 2D Barcode image in .NET framework applications. www.OnBarcode.comIMPORTANT
Barcode Creation In Objective-C Using Barcode maker for iPhone Control to generate, create bar code image in iPhone applications. www.OnBarcode.comCreating ECC200 In Java Using Barcode generator for Android Control to generate, create Data Matrix image in Android applications. www.OnBarcode.comLab requirements
1D Barcode Generator In Java Using Barcode creator for Java Control to generate, create Linear 1D Barcode image in Java applications. www.OnBarcode.comDraw QR Code 2d Barcode In Java Using Barcode printer for Java Control to generate, create QR Code image in Java applications. www.OnBarcode.comYou will need to have SQL Server 2005 and the AdventureWorks database installed before you can complete this lab. Refer to the Introduction for setup instructions. Code-128 Generator In VS .NET Using Barcode maker for Reporting Service Control to generate, create Code 128A image in Reporting Service applications. www.OnBarcode.comBar Code Printer In Java Using Barcode creation for Eclipse BIRT Control to generate, create bar code image in Eclipse BIRT applications. www.OnBarcode.comExercise 1: Test Using a Small Result Set In this exercise, you will execute the three queries mentioned in the lab preface and record each query s cost. In this case, the parameter supplied to all three queries (TerritoryID) will yield a small result set of 64 rows. 1. Open SQL Server Management Studio and connect to an instance of SQL Server 2005. 2. In a new query window, type and execute the following SQL statements to create the TestDB database, the Test schema, and the two tables that will be used in this exercise: CREATE DATABASE TestDB; GO USE TestDB; GO CREATE SCHEMA Test; GO SELECT * INTO Test.SalesOrderHeader FROM AdventureWorks.Sales.SalesOrderHeader; GO SELECT * INTO Test.Customer FROM AdventureWorks.Sales.Customer; GO ALTER TABLE Test.SalesOrderHeader Lesson 1: Optimizing and Tuning Queries
ADD CONSTRAINT PKSalesOrderHeader PRIMARY KEY(SalesOrderID); GO ALTER TABLE Test.Customer ADD CONSTRAINT PKCustomer PRIMARY KEY(CustomerID); 3. Turn on the Actual Execution Plan in SQL Server Management Studio by pressing Ctrl+M, or by selecting Include Actual Execution Plan from the Query menu. 4. Type and execute Query #1 to test its performance. (Because of the use of two separate correlated subqueries in this query, it is not guaranteed that both these subqueries return data from the same row in the Test.Customer table.) -- Query #1 SELECT c.CustomerID ,c.AccountNumber ,( SELECT TOP(1) soh.SalesOrderID FROM Test.SalesOrderHeader AS soh WHERE soh.CustomerID = c.CustomerID ORDER BY OrderDate DESC ) AS SalesOrderID ,( SELECT TOP(1) soh.OrderDate FROM Test.SalesOrderHeader AS soh WHERE soh.CustomerID = c.CustomerID ORDER BY OrderDate DESC ) AS OrderDate FROM Test.Customer AS c WHERE c.TerritoryID = 2; What was the total cost of Query #1 (You can find the value in the Execution Plan tab by moving the mouse pointer over the SELECT operator and locating the value named Estimated Subtree Cost.) 5. Type and execute Query #2 to test its performance. -- Query #2 SELECT c.CustomerID ,c.AccountNumber ,o.* FROM Test.Customer AS c OUTER APPLY ( SELECT TOP(1) soh.SalesOrderID, soh.OrderDate FROM Test.SalesOrderHeader AS soh WHERE soh.CustomerID = c.CustomerID ORDER BY OrderDate DESC 7
Optimizing SQL Server 2005 Performance
) AS o WHERE c.TerritoryID = 2; What was the total cost of Query #2 6. Type and execute Query #3 to test its performance.
-- Query #3 WITH a AS ( SELECT c.CustomerID ,c.AccountNumber ,c.TerritoryID ,soh.SalesOrderID ,soh.OrderDate ,ROW_NUMBER() OVER (PARTITION BY c.CustomerID ORDER BY soh.OrderDate DESC) AS RowNo FROM Test.Customer AS c LEFT OUTER JOIN Test.SalesOrderHeader AS soh ON soh.CustomerID = c.CustomerID ) SELECT a.CustomerID ,a.AccountNumber ,a.SalesOrderID ,a.OrderDate FROM a WHERE a.RowNo = 1 AND a.TerritoryID = 2; What was the total cost of Query #3 7. To clean up after this exercise, close all open query windows in SQL Server Management Studio, open a new query window, and execute the following SQL statements: USE master; DROP DATABASE TestDB; Exercise 2: Test Using a Large Result Set In this exercise, you will execute the three queries mentioned in the lab preface and record each query s cost. In this case, the parameter supplied to all three queries (TerritoryID) will yield a larger result set of 3,433 rows (compared to 64 rows in the previous exercise). 1. Open SQL Server Management Studio and connect to an instance of SQL Server 2005. 2. In a new query window, type and execute the following SQL statements to create the TestDB database, the Test schema, and the two tables that will be used in this exercise:
|
|