运行 每次 SQL 服务器代理作业运行时查询

Run query every time a SQL Server Agent job runs

我有大约 100 个 SQL 服务器代理作业 运行 按计划进行。我需要一种方法来执行查询并在每次这些作业 运行 中将结果转储到 table 中。像

[Job Name], [Success/Fail], [Time] etc. 

table 是一个自定义 table 但我可以灵活使用它。 Google 找到了所有错误方向的答案。

为什么不检查 SQL 服务器代理的日志文件?

View SQL Server Agent Error Log

也可以手动查询dbo.sysjobhistory and/or dbo.sysjobactivity:

dbo.sysjobhistory

Contains information about the execution of scheduled jobs by SQL Server Agent. This table is stored in the msdb database.

dbo.sysjobactivity

Records current SQL Server Agent job activity and status.

SELECT *
FROM msdb.dbo.sysjobhistory

SELECT *
FROM msdb.dbo.sysjobactivity