Schedule a SQLAgent job using t-sql

  • Hi,

    I have backup job called TestBackup and I want to schedule it to run at 3:00 PM using t-sql.

    I know how to do this from SSMS. But I want to schedule this job using t-sql.

    Please advice

    Thanks

  • You can script any job and check the script to see how to schedule a job or read in BOL about sp_add_jobschedule

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Right click on an existing job and select "Script job as". This will create the script for you. You may use this script as an example and do the changes as needed

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • Thank you,

    I ran the below query to schedule the job Test_Backup to run at 11:45 AM.

    USE msdb

    EXEC sp_add_jobschedule @job_name = 'Test_Backup',

    @name = 'Full',

    @freq_type = 1, -- daily

    @freq_interval = 1,

    @active_start_time = 114500

    The job Test_Backup has already have job step (Test_Backup->Properties->Schedule->here, under schedule list, I have a scheduled item that configured earlier named as Full and when I ran the above query it adding one more step under schedule list to run at 11:45 am.

    Is there way not to create one more step under schedule list and overwrite the existing schedule? please see the attachment.

    Thank you

  • If you want to update the scheduled time via tsql use sp_update_jobschedule

    ---------------------------------------------------------------------

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

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