在sql server 2008中创建作业 [英] creating job in sql server 2008

查看:139
本文介绍了在sql server 2008中创建作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理应用程序,其中我希望我的值每月更新,但应该基于一些计算。如果我创建相同的工作然后我将在该工作中应用更新逻辑。我的问题是在哪里应用逻辑用于计算?

I am working with application in which i want my values updated every month,but should be based on some calculations.if i create job for the same then i would apply update logic in that job.my question is where to apply logic for calculation?

推荐答案

查看一些主题:

创建SQL Server代理作业 [ ^ ]

安排工作 [ ^ ]

创建工作 [ ^ ]



如何在sql server中创建作业 [ ^ ]

每半小时执行一次存储过程。 [ ^ ]

SQL Server 2008 - 创建和安排工作

使用SQL Server 2008调度自动备份

如何:安排作业(SQL Server Management Studio)
Check out some threads:
Creating SQL Server Agent Jobs[^]
Schedule a Job[^]
Create a Job[^]

How to create a job in sql server[^]
Execution of Stored Procedure for every half an hour.[^]
SQL Server 2008 -Create and Schedule Job
Scheduling automated backup using SQL server 2008
How to: Schedule a Job (SQL Server Management Studio)






你可以迭代作业属性中的计算 - >步骤 - >然后编辑命令并通过计算编写更新查询。


you can write the calculation in job properties->Step->then edit the command and write the update query with calculation.


嗨填写以下步骤:



1.打开SSMS和一个新的查询窗口

2.复制并执行以下脚本:



Hi fillow the steps below:

1.Open SSMS and a new query window
2.Copy and execute the script below:

USE [msdb]
GO

/****** Object:  Job [UpdateMyCalculation]    Script Date: 2/19/2013 4:36:20 PM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]]    Script Date: 2/19/2013 4:36:20 PM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N''[Uncategorized (Local)]'' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N''JOB'', @type=N''LOCAL'', @name=N''[Uncategorized (Local)]''
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N''UpdateMyCalculation'', 
		@enabled=1, 
		@notify_level_eventlog=0, 
		@notify_level_email=0, 
		@notify_level_netsend=0, 
		@notify_level_page=0, 
		@delete_level=0, 
		@description=N''No description available.'', 
		@category_name=N''[Uncategorized (Local)]'', 
		@owner_login_name=N''sa'', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [UpdateTable]    Script Date: 2/19/2013 4:36:21 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N''UpdateTable'', 
		@step_id=1, 
		@cmdexec_success_code=0, 
		@on_success_action=1, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N''TSQL'', 
		@command=N''UPDATE Test SET Col1=Col*100 WHERE Col1>100'', 
		@database_name=N''TestAyncDB'', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N''ScheExe_Occur_Once_In_a_Month'', 
		@enabled=1, 
		@freq_type=16, 
		@freq_interval=1, 
		@freq_subday_type=1, 
		@freq_subday_interval=0, 
		@freq_relative_interval=0, 
		@freq_recurrence_factor=1, 
		@active_start_date=20130219, 
		@active_end_date=99991231, 
		@active_start_time=0, 
		@active_end_time=235959, 
		@schedule_uid=N''408c319f-8a01-487d-be63-074c1342f986''
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N''(local)''
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:

GO





3.编辑以下部分



3. Edit the following section

@command=N''UPDATE Test SET Col1=Col*100 WHERE Col1>100'',





并将你的SQL语句改为UPDATE Test SET Col1 = Col * 100 WHERE Col1> 100



4.执行脚本,a将创建作业,此作业将在一个月内运行一次。

5.如果您需要更改计划(1个月),那么

5.1转到SQL Server代理

5.2右键单击工作

5.3选择管理时间表

5.4选择ScheExe_Occur_Once_In_a_Month并点击属性



享受!!!!!



and put your SQL statement instead of "UPDATE Test SET Col1=Col*100 WHERE Col1>100"

4. Execute the script, a Job will be created and this job will run once in a month.
5. If you need to change the schedule (1 month) then
5.1 Go to SQL Server Agent
5.2 Right click on Job
5.3 Choose Manage Schedule
5.4 Select "ScheExe_Occur_Once_In_a_Month" and Click on "Properties"

Enjoy!!!!!


这篇关于在sql server 2008中创建作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆