Flylib.com

Books Software

 
 
 

Quick Check


Quick Check

1. 

Which caching method is easy to implement but allows you the most control in how it is implemented?

image from book

2. 

What new feature with SQL Server 2005 enables you to receive notifications when the data in your cache has been updated?

image from book

3. 

What are some commonly used alternatives to using a server-side cursor?

image from book

4. 

Which two statements should be executed after all the rows in your cursor are fetched ?

image from book

5. 

Which concurrency option should be avoided to minimize blocking?

image from book

Answers

1.  

Control level-caching is easily implemented by adding the OutputCache directive to the top of the HTML. By using control level-caching as opposed to page level-caching, you have more control over what is cached in your Web page.

2.  

Query notifications allow you to receive notifications when the data in your cache has been updated. You can then execute a refresh of the cache and ensure that you have the latest version of the data.

3.  

Often, you can replace a cursor with a single SELECT statement. You can also consider using a WHILE loop, CASE function, and a recursive query.

4.  

You should always include the CLOSE and DEALLOCATE statements after all the data in your cursor has been fetched. This will release all locks and also remove the cursor from server memory.

5.  

The SCROLL_LOCKS option should be avoided, because it assumes updates might occur to the data before the cursor has been closed. Depending on the lock hints specified in the SELECT statement, locks might be issued on the underlying tables by using this option.



Case Scenario: Evaluating Cursor Performance

 

In the this case scenario, you are a database developer for a large financial company that provides mortgages to people with poor credit ratings. For the past three years , the company has been utilizing a complex ASP.NET application that retrieves data from a SQL 2000 database. As the amount of data in the database increased, company employees have noticed that the application response time has decreased.

The company now intends to move the data to a SQL 2005 database. They would like for you to analyze the solution and recommend ways that the application can be improved. Upon reviewing the SQL code, you notice that a cursor is used in about half the stored procedures. What strategy might you recommend for improving database performance?

image from book

Answers

 

It might not be necessary to replace all the cursors in this poorly performing application. The best place to start is by identifying those areas of the application that are experiencing the largest delays. You could use SQL Server Profiler to record a trace while the application executes some of the slower functions. The trace recording can be used as input for the Database Engine Tuning Advisor, as an alternative to replacing the cursor. You might be able to resolve the application problems by simply applying a few indexes.

If the application performance continues to suffer, then you should consider replacing some of the cursors with set-based alternatives. You would start by identifying those cursors that take the longest to execute. For these long-running stored procedures, try to find a way to replace the cursor with one of the alternatives mentioned in Lesson 2, "Designing a Cursor Strategy." Compare the execution times for the alternative with the original cursor to determine if the change was successful. You might just have to do this procedure with a few of the cursors to achieve the desired performance results. There is a tradeoff to consider between development time and application performance.