分享方式:


jobs.sp_stop_job (Azure 彈性作業) (Transact-SQL)

適用於:Azure SQL 資料庫

指示彈性作業代理程式在適用於 Azure 的 Azure 彈性作業服務中停止作業執行 SQL 資料庫

這個預存程式會與 SQL Server Agent 服務中的類似物件共用 的名稱 sp_stop_job 。 如需 SQL Server Agent 版本的相關信息,請參閱 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) 固定伺服器角色的成員,才能夠執行這個預存程序。 只有系統管理員的成員可以使用此預存程序來編輯其他使用者所擁有的作業屬性。

備註

彈性作業的所有時間都在UTC時區。

若要識別 job_execution_id 目前作業執行的 ,請使用 jobs.job_executions

範例

識別並停止作業執行

下列範例示範如何在 jobs.job_executions 中識別作業執行,然後使用 來取消作業執行job_execution_id,例如 01234567-89ab-cdef-0123-456789abcdef

連結至 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';