我们如何仅删除 1 天的 SQL 代理作业历史记录(对于作业)?
例如,我只想删除 9 月 1 日
最佳答案
sp_purge_jobhistory 是 Microsoft 提供的清除作业历史记录的工具,它以日期作为参数之一。
sp_purge_jobhistory
{ [ @job_name = ] 'job_name' |
| [ @job_id = ] job_id }
[ , [ @oldest_date = ] oldest_date ]
现在查看日期文档,它在下面说明
The oldest record to retain in the history. oldest_date is datetime, with a default of NULL. When oldest_date is specified, sp_purge_jobhistory only removes records that are older than the value specified.
根据上面的文档,你不能删除一天..
但是查看源代码,我看到它所做的只是检查权限并在行下运行
DELETE FROM msdb.dbo.sysjobhistory
WHERE ((run_date < @datepart) OR
(run_date <= @datepart AND run_time < @timepart))
所以你可以通过,run_date =date
你需要删除
关于SQL Server 代理作业历史记录 - 仅删除一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39416163/