Question

Asked:
Asked By:
Jul 11 2008   2:52 PM GMT
SQL Server Ask the Experts   2275 pts.

Running a stored procedure in SQL Query Analyzer or as part of a SQL job


SQL Server 2000, Stored Procedures, SQL Query Analyzer

I have been trying to run a stored procedure in SQL Query Analyzer and as a step in a SQL job. If I run it in Query Analyzer, it takes less than a minute, but it takes considerably longer if it is run as a step. I use SQL Server 2000. Why would there be so big a difference?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



About the only difference between the two will be the ANSI settings of the session. Query Analyzer will turn a few settings on when running the procedure. The SQL Agent doesn't turn any on, and uses the server default unless you specify any in the job step properties. These different settings will force the SQL Server to use a different execution plan for the SQL Agent as it uses for you.

Setup SQL Profiler and have it monitor the SQL Server, then run the job. Have SQL Profiler give you the execution plan which is being used so that you can see exactly what it's doing.

You may find that you need to add the same ANSI Settings to the SQL Agent job.

It could also be because database maintenance is being performed at the time that the job is running, and that maintenance is not being run when you run the procedure during the day. Check for other jobs which are running at the same time as the SQL Agent job which is having the performance problem.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on SQL Server.

Looking for relevant SQL Server Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Mrdenny   41270 pts.  |   Sep 9 2008  9:48AM GMT

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.