如何在SQL Server 2005中创建作业和计划

时间:2012-04-30 15:50:45

标签: sql-server-2005

我的问题是我在计算机上安装了SQL Server 2005。我想创建工作和计划​​以自动设置我的商店程序。但问题是它需要我先创建SSIS。绝对我无法配置它。我想知道我可以在我的电脑上配置它(不是窗口服务器只是Window 7)吗?这是我的SQL Server版本:

  Microsoft SQL Server Management Studio               9.00.1399.00
  Microsoft Analysis Services Client Tools             2005.090.1399.00
  Microsoft Data Access Components (MDAC)              6.1.7601.17514(win7sp1_rtm.101119-1850)
  Microsoft MSXML                                      3.0 4.0 5.0 6.0 
  Microsoft Internet Explorer                          9.0.8112.16421
  Microsoft .NET Framework                             2.0.50727.5448
  Operating System                                     6.1.7601

提前谢谢你......

1 个答案:

答案 0 :(得分:0)

生成JOB并将其分配给对象的典型脚本(如存储过程)如下所示......

DECLARE @JobID BINARY(16)
EXECUTE msdb.dbo.sp_add_job @job_id = @JobID OUTPUT,
                            @job_name = N'<<A NAME OF YOUR JOB>>',
                            @enabled = 1,
                            @owner_login_name = N'@YOURLOGINCREDENTIALS',
                            @description = N'No description available.',
                            @category_name = N'[Uncategorized (Local)]',
                            @notify_level_eventlog = 0,
                            @notify_level_email = 2,
                            @notify_email_operator_name = N'<<OPTIONAL>>',
                            @notify_level_netsend = 0,
                            @notify_level_page = 0,
                            @delete_level = 0;
EXECUTE msdb.dbo.sp_add_jobstep @job_id = @JobID,
                                @step_id = 1,
                                @step_name = N'spMYPROCEDURE',
                                @command = N'EXEC spMYPROCEDURE',
                                @database_name = N'<<MASTER OR WHAT EVER YOUR DATABASE IS>>',
                                @subsystem = N'TSQL',
                                @flags = 6,
                                @retry_attempts = 3,
                                @retry_interval = 5,
                                @output_file_name = N'<<WHERE YOU WANT TO SAVE A LOG FILE OF THE JOB>> \spMYPROCEDURE.jobresults.log',
                                @on_success_step_id = 0,
                                @on_success_action = 1,
                                @on_fail_step_id = 0,
                                @on_fail_action = 2;
EXECUTE msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1;
EXECUTE msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(LOCAL)';
EXECUTE msdb.dbo.sp_add_jobschedule @job_id = @JobID,
                                    @name = N'spMYPROCEDURE',
                                    @enabled = 1,
                                    @freq_type = 8,
                                    @active_start_date = 20140417,
                                    @active_end_date = 99991231,
                                    @freq_interval = 62,
                                    @freq_subday_type = 1,
                                    @freq_subday_interval = 1,
                                    @freq_relative_interval = 1,
                                    @freq_recurrence_factor = 1,
                                    @active_start_time = 90000,
                                    @active_end_time = 235959;
GO

通常我会首先创建存储过程,测试并运行它以确保它正常工作,然后为其分配作业,如上所示。

注意@active时间都是完整的整数小数(即:90000 = 09:00:00 am)

在运行上述脚本之前,您可能还需要USE [master]作为数据库参考。