Solved

T sql script to alter SQL Server agent job if exists

Posted on 2014-01-12
6
2,347 Views
Last Modified: 2014-01-27
Hi Experts,

  Could you please help me with T-Sql script to alter SQL Server agent job.  If the job exists, then I need to alter the job script ,to  add more steps and also edit the existing steps.  
I don't want to add it manually through wizard as we want to run the T-Sql scripts only (as we don't have access to production environments)

I need a sample Alter script . Your help is greatly appreciated in this regard.

Please Note : I don't want to drop and create the existing job in production as I would loose history of the job.

Regards,

Sreekanth.
0
Comment
Question by:n_srikanth4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39775430
I would go through the steps with the wizard, just don't finish and instead save the SQL Scripts off so that you can optionally edit them and have them ultimately run in Production.

Let me know if you need help with that.
0
 

Author Comment

by:n_srikanth4
ID: 39775464
Hi Savant ,

     I could not go through the wizard , It will just add the step , but not generate any script .  Secondly , the  jobs are already created in Dev server , so i cannot undo the wizard.  So could you please walk through an example sample script please.

Regards,

Srk.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39775503
i would drop the step in development and start again using the wizard, but this time save the SQL scripts, before you finish.

P.S.  The name is Anthony (you will see it as it is just below where it says "Your Comment" and after "by:")
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 39775517
My suggestion is that you create your own "history" table that you write the results to as the steps run. Basically as the first part of that particular step you insert the step name, time, server, db and other details at the beginning into the history table. Then at the end of the step you have a similar insert statement.

That way you aren't dependent on the job history table.

Then adding steps or replacing the script you don't lose the history. And if you build out the script for more stuff, you can just hand it off to the production team and move on.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39781034
Hi,

If you examine the script of the existing job, that script should have all the clues you need. That is, the job steps are added to the job one at a time. Of course you'll have to add logic that finds how many existing steps there are, and appends them. And don't forget to modify existing last step to go on to the next on success.

HTH
  David
0
 

Author Closing Comment

by:n_srikanth4
ID: 39813554
good
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question