How to delete a server agent job after completion?

  • I have a stored procedure that I want to schedule to run overnight on an addhoc basis. I have worked out how to schedule the job from another stored procedure which anyone can run at any time, using sp_add_job, sp_add_jobschedule, etc. so that the job will execute at 01:00 am.

    My dilemma is how to delete this job after it has executed.

    Any suggestions??

  • Not sp_delete_job and sp_delete_jobschedule, presumably? Is it that you want the final part of your job to be self-deletion?

    Phil

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Yes, I want the final part of my job to self-delete. I tried sp_delete_job which appeared to partially remove the job, ie. in EM the job still appeared in the list but if I attempt to edit the job I get the message "Job xxx does not exist on the Server".

    Do I also need to do a sp_delete_jobschedule?

    I assumed SQL would not let a job delete itself.

    Regards, Ian

  • Did a bit more research! Thanks for the hint, Phil. I needed to do a sp_delete_job and sp_delete_jobschedule.

    Regards,

    Ian

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply