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. 6 个轻量级并且灵活的 PHP CMS 系统

    Anchor CMS Just like its introduction says, Anchor has a very simple UI. The installation takes lite ...

  2. 全排列算法之Perm算法实现

    题目描述:   给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列.   我们假设对于小写字母有'a' < 'b' < … < 'y' < 'z',而且给定的字符 ...

  3. stdarg.h详解

    读Linux内核中的vsprintf函数的时候遇到了C语言的可变参数调用,查了挺多资料还是这篇比较详细,而且自己验证了下,确实如此 (一)写一个简单的可变参数的C函数  下面我们来探讨如何写一个简单的 ...

  4. Purpose of requirePermission attribute (web.config)

    requirePermission 属性的含义 https://msdn.microsoft.com/en-us/library/system.configuration.sectioninforma ...

  5. android ConnectivityManager 检查是否有网络

    一.   ConnectivityManager 概要 ConnectivityManager是网络连接相关的管理器,它主要用于查询网络状态并在网络发生改变时发出状态变化通知.这个类主要负责的下列四个 ...

  6. Spark 资源调度及任务调度

    1.  资源分配 通过SparkSubmit进行提交应用后,首先会创建Client将应用程序(字节码文件.class)包装成Driver,并将其注册到Master.Master收到Client的注册请 ...

  7. js 中比较 undefined

    // x has not been declared before if (typeof x === 'undefined') { // evaluates to true without error ...

  8. Boost编程之获取可执行文件的当前路径

    #include <boost/filesystem/path.hpp> #include <boost/filesystem/operations.hpp> std::str ...

  9. DLL模块:extern "C"的简单解析

    1.揭密extern "C" extern "C"包含双重含义,从字面上即可得到:首先,被它修饰的目标是 "extern”的:其次,被它修饰的目标是 ...

  10. ASCII码表(0 - 255)

    目前计算机中用得最广泛的字符集及其编码,是由美国国家标准局(ANSI)制定的ASCII码(American Standard Code for Information Interchange,美国标准 ...