我可以在同一个表上有两个不同的插入触发器吗?
它们似乎是被允许的,因为我可以看到表下列出的两个插入触发器具有不同的名称。这是常见的还是不好的做法?我正在使用 SQL Server 2005
They seem to be allowed as I can see both my insert triggers listed under the table with different names. Is it common or a bad practice? I am using SQL Server 2005
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,每个操作肯定可以有多个触发器,例如 AFTER INSERT 或 AFTER UPDATE 等。将单独的关注点分成单独的、小的、可管理的代码块。
您不能依赖的一件事是它们将按一定的顺序执行 - 触发器确实执行的顺序也不必是稳定的,即每次都相同。
Yes, you can definitely have more than one trigger for each operation, e.g.
AFTER INSERT
orAFTER UPDATE
etc. It does make sense to split up separate concerns into separate, small, manageable chunks of code.The one thing you cannot rely on is that they'll be executed in a certain order - the order in which the triggers are indeed executed also doesn't have to be stable, i.e. the same every time around.
这是一个很好的做法,因为这样您就可以将随着时间的推移所做的更改分解为小(敏捷)块,并相互独立地添加或删除它们。
it's a good practice because then you can break down your changes over time into little (agile) chunks and add or remove them independently of each other.