Automatically generate next month database based on monthly database--3

Source: Internet
Author: User
Data | database


--Create a job for the last day of the month, invoke the stored procedure above to automatically create the database

Use Mastergo

--Set the SQL Agent service to automatically start exec msdb. Sp_set_sqlagent_properties @auto_start =1go

--Create job exec msdb ... Sp_add_job @job_name =n ' automatic database processing '

--Create job step declare @sql varchar, @dbname varchar Select @sql =n ' exec sp_proccopydb '-Invoke stored procedures for automated libraries, @dbname =db_ Name ()--database name to perform automatic library processing

EXEC msdb.. Sp_add_jobstep @job_name =n ' automatic database processing ', @step_name = ' database processing ', @subsystem = ' TSQL ', @database_name = @dbname, @command = @sql, @ Retry_attempts = 5,--Retries @retry_interval = 5--Retry interval

--Add job schedule (last weekday per month) EXEC msdb.dbo.sp_add_jobschedule @job_name = n ' Automatic database processing ', @name = n ' time schedule ', @freq_type = +, @active_ start_time = 0,--0 points begin execution @freq_interval = 9,--the last weekday of the month @freq_subday_type = 1, @freq_subday_interval = 0, @freq_relat Ive_interval = @freq_recurrence_factor = 1

--Add target server exec msdb.dbo.sp_add_jobserver @job_name = n ' Automatic database processing ', @server_name = N ' (local) '

/*--Known Issues

Some databases may not be able to be processed using the method of generating scripts due to SQL generated script bugs

--*/


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.