CREATE Proc [dbo].[Proc_StopJob]
as
begin
declare @I int
declare @JobID uniqueidentifier
-- 1. create temp table to save jobs status
create table #job_run_status
(
job_id uniqueidentifier not null,
last_run_date int not null,
last_run_time int not null,
next_run_date int not null,
next_run_time int not null,
next_run_schedule_id int not null,
requested_to_run int not null, -- bool
request_source int not null,
request_source_id sysname collate database_default null,
running int not null, -- bool
current_step int not null,
current_retry_attempt int not null,
job_state int not null
)
-- 2. get jobs status
insert into #job_run_status
execute master.dbo.xp_sqlagent_enum_jobs 1, 'sa'
-- 3. get running jobs
select job_name = j.name
,s.*,ROW_NUMBER() over (order by j.name) as ID
into #RunJob
from #job_run_status s
inner join msdb.dbo.sysjobs j
on s.job_id = j.job_id
where s.running = 1 -- running = 1
--4.停止运行作业
select @I=COUNT(*) from #RunJob while @I>0
begin
select @JobID=job_id from #RunJob where ID=@I
exec msdb.dbo.sp_stop_job '',@JobID
set @I=@I-1
end
end

Sql Server批量停止作业的更多相关文章

  1. SQL Server 批量主分区备份(Multiple Jobs)

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 案例分析(Case) 方案一(Solution One) 方案二(Solution Two) ...

  2. SQL Server 批量完整备份

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 实现方式一(One) 实现方式二(Two) 实现方式三(Thr ...

  3. SQL Server 批量主分区备份(One Job)

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 案例分析(Case) 实现代码(SQL Codes) 主分区完整.差异还原(Primary B ...

  4. SQL Server 批量创建作业(备份主分区)

    一. 需求背景 在我的数据库实例中,有很多类似下图所示的数据库,这些数据库的名称是有规律的,每个数据库包含的表都是相同的,其中2个表是类似流水记录的表,表的数据量会比较大,占用的空间有几十G到上百G不 ...

  5. SQL Server批量数据导出导入Bulk Insert使用

    简介 Bulk insert命令区别于BCP命令之处在于它是SQL server脚本语句,它可以将本地或远程的文件数据批量导入数据库,速度非常之快:远程文件必须共享才行, 文件路径须使用通用约定(UN ...

  6. SQL Server 批量插入数据的两种方法

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍 SQL Server支持的两种批 ...

  7. SQL Server 批量插入数据的两种方法(转)

    此文原创自CSDN TJVictor专栏:http://blog.csdn.net/tjvictor/archive/2009/07/18/4360030.aspx 在SQL Server 中插入一条 ...

  8. 转:SQL Server 批量插入数据的两种方法

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍SQL Server支持的两种批量 ...

  9. SQL SERVER 批量生成编号

    开始: 在testing中,为了模拟orders,有个要求给数据库dba,如何通过后台数据库脚本快速批量生成orders. 分析 站在数据库角度,批量生成orders,也就是批量生成表中的行数据. s ...

随机推荐

  1. 网站(Tomcat)超线程宕机

    网站大中午的又挂了····· 拷了日志如下: 2014-4-12 13:22:30 org.apache.tomcat.util.net.JIoEndpoint createWorkerThread信 ...

  2. 转:fopen与open可以转换吗

    绝对不可以.fopen是C运行库级别的函数,而open是system call的wrapper routine.fopen返回FILE *的指针,这个结构本身维护着一些关于这个文件的信息,而open返 ...

  3. 健身计划_from85to75

    第一天没什么好写的,这半年也没看什么书,就写写未来的规划好了. 当然是从最简单的健身计划开始写咯. 关键词:弹性 目标:减肥,上肢力量 时间:3-4次/周(Thur,Fri,Sat,Sun),1h-1 ...

  4. C 語言中的編譯指示 (Pragma)

    編譯指示 #pragma 是用來告知編譯器某些特殊指示,例如不要輸出錯誤訊息,抑制警告訊息,或者加上記憶體漏洞檢查機制等.這些指示通常不是標準的 C 語言所具備的,而是各家編譯器廠商或開發者所制定的, ...

  5. log4jdbc

    log4jdbc http://www.blogjava.net/badqiu/archive/2010/08/20/329464.html http://blog.csdn.net/sfdev/ar ...

  6. TCP 协议

    == 已经了解了以太网和IP了,下面我们进入传输层,开始讲解TCP协议. == 仍然先把TCP报文段的格式放在这里,然后我们看图说话: TCP报文段也分为首部和数据两部分,首部默认情况下一般是20字节 ...

  7. HDU-5504(逻辑if-else大水题)

    Problem Description You are given a sequence of N integers. You should choose some numbers(at least ...

  8. SpringMVC 拦截器(interceptors)对样式(css),JavaScript(js),图片(images)链接的拦截

    因为在web.xml配置了 <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pa ...

  9. android 分辨率自适应

    1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机是3.7英寸 A ...

  10. ajax弹出窗口

    提取自ZCMS的弹出框: 代替window.open.window.alert.window.confirm:提供良好的用户体验: 水晶质感,设计细腻,外观漂亮: 兼容ie6/7/8.firefox2 ...