jobs.sp_stop_job (Azure 弹性作业) (Transact-SQL)

适用于:Azure SQL 数据库

指示弹性作业代理在 Azure 弹性作业服务中停止作业执行,以便Azure SQL 数据库

此存储过程与 SQL Server 中用于SQL Server 代理服务的类似对象共享名称sp_stop_job。 有关SQL Server 代理版本的信息,请参阅sp_stop_job(Transact-SQL)。

Transact-SQL 语法约定

语法

[jobs].sp_stop_job [ @job_execution_id = ] ' job_execution_id '

参数

@job_execution_id

要停止的作业执行操作的标识号。 job_execution_id 为 uniqueidentifier,默认值为 NULL.

返回代码值

0(成功)或 1(失败)

权限

默认情况下,只有 sysadmin 固定服务器角色的成员才可以执行此存储过程。 仅 sysadmin 的成员可以使用此存储过程来编辑其他用户拥有的作业的属性。

注解

弹性作业中的所有时间均处于 UTC 时区。

若要标识 job_execution_id 当前作业执行,请使用 jobs.job_executions

示例

标识和停止作业执行

下面的示例演示如何识别jobs.job_executions中的作业执行,然后使用例如取消01234567-89ab-cdef-0123-456789abcdef作业执行job_execution_id

连接到 job_database,然后运行以下命令:

--Connect to the job database specified when creating the job agent

-- View all active executions to determine job_execution_id
SELECT job_name
, job_execution_id
, job_version
, step_id
, is_active
, lifecycle
, start_time
, current_attempts
, current_attempt_start_time
, last_message
, target_group_name
, target_server_name
, target_database_name
FROM jobs.job_executions
WHERE is_active = 1 AND job_name = 'ResultPoolsJob'
ORDER BY start_time DESC;
GO

-- Cancel job execution with the specified job_execution_id
EXEC jobs.sp_stop_job '01234567-89ab-cdef-0123-456789abcdef';