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

Tags:
SQL Query Analyzer
SQL Server 2000
Stored Procedures
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?
ASKED: July 11, 2008  2:52 PM
UPDATED: September 9, 2008  9:48 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following