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. iOS开发之UIWebView自动滑动到顶部-备

    但可以通过subview来操作. 通常用UIWebView加载网页,有时候需要点击一个按钮,或者页面的某个部位,使页面自动滚动到顶部,但是UIWebView不像UIScrollView那么方便.   ...

  2. AE-模板替换->愉快今日--视频样片!

  3. 2015第29周五AOP

    AOP使用场景 AOP用来封装横切关注点,具体可以在下面的场景中使用: Authentication 权限 Caching 缓存 Context passing 内容传递 Error handling ...

  4. libvirt TLS

    博客原文 http://hi.baidu.com/wwfmarcpjkbdiod/item/7b43c89e949d7fbbcd80e590 构建Libvirt的x509证书远程tls连接http:/ ...

  5. 记npm包开发全过程

    概述 为什么开发npm包? 如何开发? 如何写单元测试? package.json 如何发布模块? 如何使用? 为什么开发npm模块? NPM的全称是Node Package Manager,是一个N ...

  6. awr报告基本操作

    1.查看当前的AWR保存策略.设置:快照间隔.保存时间. SQL> col SNAP_INTERVAL format a20    SQL> col RETENTION format a2 ...

  7. memcached学习——大纲简介 && 安装(基于centos6.5)、启动、关闭memcached(一)

    大纲简介 安装前,先简单介绍一下memcached. memcached是一个免费.开源.高性能的分布式缓存.设计memcached的初衷是为了加快web应用程序,减少DB负载. 安装要求:支持大多数 ...

  8. 【转】 基于TFTP协议的远程升级设计

    版权声明:本文为博主原创文章,未经博主允许不得转载.联系邮箱:zhzhchang@126.com 说明:由于CSDN博客编辑器对word格式近乎不支持,因此对表格使用了图片方式(最后一个表格未使用图片 ...

  9. 移动端页面V2.0项目改版总结

    移动端页面已经进行的第三次改版,这个版本遇到的最大难题就是页面跳转的问题. 项目需求: 页面上有分别有优惠估价.我要估价.历史竞拍这三个Tab选项卡,当用户点击估价,选择品牌以后,前端需要去请求品牌接 ...

  10. (转)Apple Push Notification Services in iOS 6 Tutorial: Part 2/2

    转自:http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2 Upda ...