Running a stored procedure in SQL Query Analyzer or as part of a SQL job
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?

Software/Hardware used:
ASKED: July 11, 2008  2:52 PM
UPDATED: September 9, 2008  9:48 AM

Answer Wiki:
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.
Last Wiki Answer Submitted:  September 9, 2008  9:48 am  by  Denny Cherry   64,550 pts.
All Answer Wiki Contributors:  Denny Cherry   64,550 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 64,550 pts.