达到特定阈值后如何执行触发器?
我有一个网络应用程序,它将无效的登录尝试记录到数据库表中。
有没有一种方法可以在表上创建一个触发器,该触发器仅在过去几个小时左右创建一定数量的记录后运行,缺少诸如 if count(*) > > 之类的东西? 100 ?
最终目标是在登录尝试失败次数异常时发送电子邮件。
I have a web app that logs invalid login attempts to a database table.
Is there a way to create a trigger on the table that only runs after a certain number of records have been created in the last hours or so, short of something like if count(*) > 100
?
The end goal is to send an email if there are an abnormal number of failed login attempts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么要有触发器?创建每 n 分钟运行一次的 SQL 代理作业。您检查在过去一小时内是否有超过 100 次无效登录尝试,如果是这样,请运行包含详细信息的数据库邮件过程,请查找 sp_send_dbmail
Why a trigger? create a SQL agent jobs that runs every n minutes. You check if in the last hour there where more than 100 invalid login attempts, if this is true run a database mail proc with the details, look up sp_send_dbmail
创建一个针对每种情况运行的触发器,并让它查看是否满足进一步操作的标准。如果不希望继续执行操作(例如,对于过去一小时内的尝试 102),您可以在另一个表中记录上次执行此类操作的时间,然后制定其必须 > 的标准。每小时 100 次失败尝试,并且距上次此类操作必须已过去一小时。
Create a trigger that runs for every case, and have it see if the criteria for further action are met. If continuing actions aren't desired (e.g. for attempt 102 in the past hour) you could record the time it last took such action in another table, then make the criteria that it must be > 100 failed attempts per hour AND it must be an hour since the last such action.
不要使用触发器来执行此操作。创建一个作业来监控过去一小时内登录失败的计数,并在超过特定阈值时发送电子邮件。让它每小时运行一次。
Don't do this with a trigger. Create a job to monitor the count of failed logins in the last hour and send an email if it is over a certain threshold. Have it run hourly.
你不能。最好的选择是将检查放在触发器本身内部。
You can't. The best option is to put the check inside the trigger itself.