对于具有外键的表,不要使用 UPDATE TRIGGER
我收到此错误:
无法在表“MYBUDGET.tbl_Income”上创建“INSTEAD OF DELETE”或“INSTEAD OF UPDATE”触发器“trig_Income_Updater”。这是因为该表有一个带有级联 DELETE 或 UPDATE 的 FOREIGN KEY。
我可以使用“用于更新”。但如何让它忽略原来的更新呢?
I get this error:
Cannot create INSTEAD OF DELETE or INSTEAD OF UPDATE TRIGGER 'trig_Income_Updater' on table 'MYBUDGET.tbl_Income'. This is because the table has a FOREIGN KEY with cascading DELETE or UPDATE.
I can use 'FOR UPDATE'. but how to make it to ignore the original update ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要忽略原始更新,您需要使用 RAISERROR,然后使用 ROLLBACK。
此处是“使用 DML AFTER 触发器强制执行PurchaseOrderHeader 和 Vendor 表之间的业务规则”部分
To ignore the origional update you will need to utilize a RAISERROR and then ROLLBACK.
Here is an example under the "Using a DML AFTER trigger to enforce a business rule between the PurchaseOrderHeader and Vendor tables" section
只需更新所需的字段,然后使用提供给触发器的“插入”和“删除”临时表“撤消”原始更新。
例如(未经测试):
“插入”表将包含新值,“删除”表包含正在更改的值。您可以连接、查询或以其他方式将它们视为实际的表。
Just update the fields you want and then "undo" the original update using the "inserted" and "deleted" temporary tables that are provided to the trigger.
For example (untested):
The "inserted" table will contain the new values, and the "deleted" table contains the values that are being changed. You can join, query and otherwise treat them as though they were actual tables.