SQL Server中的简单每日计划任务

时间:2013-02-11 21:14:48

标签: sql sql-server sql-server-2008 tsql

USE msdb ;
GO
EXEC dbo.sp_add_job
    @job_name = N'Daily Reset of LogIn User Data';
GO
EXEC sp_add_jobstep
    @command = N'UPDATE COMMAND', 
    @retry_attempts = 5,
    @retry_interval = 5 ;
GO
EXEC dbo.sp_add_schedule
    @schedule_name = N'RunDaily',
    @freq_type = 4,
    @active_start_time = 000000 ;
USE msdb ;
GO
EXEC sp_attach_schedule
   @job_name =  N'Daily Reset of LogIn User Data', 
   @schedule_name = N'RunDaily';
GO
EXEC dbo.sp_add_jobserver
    @job_name =  N'Daily Reset of LogIn User Data';
GO

我无法弄清楚如何在@command;

中插入更新命令

我的命令是

UPDATE MyUserTable SET IsActive='N' WHERE IsActive='Y'

1 个答案:

答案 0 :(得分:1)

你可以这样做:

DECLARE @UpdateCommand NVARCHAR(200)
SET @UpdateCommand = 'UPDATE MyUserTable SET IsActive=''N'' WHERE IsActive=''Y'''

EXEC sp_add_jobstep
    @command = @UpdateCommand, 
    @retry_attempts = 5,
    @retry_interval = 5 ;