Day 16

Quiz

1:When could a stored procedure cause serious performance problems?
A1: Stored procedures can cause problems when a stored optimization plan is unsuitable for the current set of parameters.
2:Can you give an example of the previous answer?
A2: Certain parameter sets will call for the use of an index, and others are better suited to a table scan. Use of the wrong optimization plan will cause a significant performance problem. You should use the RECOMPILE option. A typical example is a search based on a date range as shown.
Create procedure sp_datename (@startdate Datetime, @enddate Datetime)
As
Select *
From tablename
Where date Between @startdate and @enddate

Exercises

1:The following procedure seems to take a long time to process. ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.