SQL job start-Stop server

Source: Internet
Author: User
IF EXISTS (SELECT * from msdb.dbo.sysjobs WHERE name= ' enable pubs database ') EXEC msdb.dbo.sp_delete_job @job_name = ' Enable Pubs database '-- Define create job declare @jobid uniqueidentifierexec msdb.dbo.sp_add_job@job_name = N ' Enable pubs database ', @job_id = @jobid output--define the job step declare @sql nvarchar, @dbname sysnameselect @dbname =n ' master ',                   -- Database online or offline can only be performed in the master database @sql=n ' ALTER database pubs SET Online '-  -use the Pubs database online (enable) EXEC msdb.dbo.sp_add_ jobstep@job_id = @jobid, @step_name = N ' Enable pubs database processing ', @subsystem = ' TSQL ', @[email protected], @command = @sql--Create schedule
EXEC msdb: sp_add_jobschedule@job_id = @jobid, @name = N ' Enable the Pubs database processing schedule ', @freq_type =4, @freq_interval =1, @freq_subday_type =0x1,@ freq_subday_interval=1, @active_start_time = 075000 – 07:50 per day – Add target server declare @servername sysnameset @servername = CONVERT (nvarchar (+), serverproperty (N ' ServerName ')) EXEC msdb.dbo.sp_add_jobserver @job_id = @jobid, @server_name = @ ServerName

SQL job start-Stop server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.