sql-server - SQL Server : delay trigger
问题描述
I have customer machine what inserts data into my SQL Server database at midnight. In SQL Server there is trigger to delete old records upon insert.
The problem is, the customer does bunch of single insert commands (instead of using bulk insert), actually hundreds of them. I cannot control that. What I did is to record last trigger time and if datediff is less than one hour, don't do anything. I read using WAITFOR
in triggers is a bad idea as it locks the table until trigger execution is done. Is there any other way? Cheers.
BEGIN
SET NOCOUNT ON;
IF DATEDIFF(HOUR, (SELECT TOP 1 TimeStamp
FROM HouseKeepingStats
ORDER BY TimeStamp DESC), GETDATE()) > 1
BEGIN
EXEC HouseKeeping;
END
END
解决方案
推荐阅读
- angular - Angular mat-datepicker 奇怪的行为
- mysql - 如何使用nodejs更新mysql json数组
- authentication - 密码重置的登录凭据在 Laravel 7 中不起作用
- scrapy - ScrapingHub 部署失败
- asp.net - 仅当为 true 时才根据需要进行字段验证
- reactjs - 反应中多次调用handleKeyPress方法
- jquery - Sinatra - 4.0.1 无法加载 JQuery - net::ERR_ABORTED 404(未找到)
- android - Android 作为 UVC 相机
- xml - 任务计划程序自定义触发器 - 当 EventID 为 FOO 且 EventData.Data 为 BAR 时启动
- nginx - Nginx 不存储缓存