对于具有外键的表,不要使用 UPDATE TRIGGER

发布于 2024-10-10 05:45:40 字数 223 浏览 0 评论 0原文

我收到此错误:

无法在表“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不咬妳我踢妳 2024-10-17 05:45:40

要忽略原始更新,您需要使用 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

虫児飞 2024-10-17 05:45:40

只需更新所需的字段,然后使用提供给触发器的“插入”和“删除”临时表“撤消”原始更新。

例如(未经测试):

--Do the stuff you want
UPDATE table SET fields = values WHERE some condition


--Undo the original update (minus anything you WANT changed above)
UPDATE table SET unchangingfield = deleted.unchangingfield WHERE ID = deleted.ID

“插入”表将包含新值,“删除”表包含正在更改的值。您可以连接、查询或以其他方式将它们视为实际的表。

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):

--Do the stuff you want
UPDATE table SET fields = values WHERE some condition


--Undo the original update (minus anything you WANT changed above)
UPDATE table SET unchangingfield = deleted.unchangingfield WHERE ID = deleted.ID

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文