如何禁用Oracle中涉及表的所有触发器?
在 Postgresql 中,如果我执行 ALTER TABLE mytable DISBLE TRIGGERS ALL ,则与此表相关的所有触发器和约束都会挂起。
特别是,从其他表到 mytable 的外键被暂停,我可以毫无问题地从 mytable 中删除。我有破坏数据库一致性的风险,但我知道我在做什么,而且我必须拥有超级用户权限。
我如何在 Oracle 中做同样的事情?我的印象是Oracle中的ALTER TABLE mytable DISBLE ALL TRIGGERS将暂停属于mytable的所有触发器和约束,但不会暂停那些涉及mytable但属于其他表(尤其是外键)的触发器和约束。
我是对的吗?如何才能达到与 Oracle 中的 Postgresql 相同的结果?
In Postgresql, if I do ALTER TABLE mytable DISBLE TRIGGERS ALL
, all triggers and constraints regarding this table are suspended.
Especially, foreign keys from other tables to mytable are suspended, and I can delete from mytable without problem. I have the risk to break database consistency, but I know what I'm doing, and I must have superuser privileges.
How do I do the same in Oracle ? I am under the impression that ALTER TABLE mytable DISBLE ALL TRIGGERS
in Oracle will suspend all trigger and constraints belonging to mytable, but not those that concerns mytable but belong to other tables (especially foreign keys).
Am I right and what would be the way to achieve the same result as in Postgresql in Oracle ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该语法确实禁用了 Oracle 中的触发器:
但是它不会对外键或任何其他约束执行任何操作。这是因为 Oracle 不使用触发器来强制执行此类操作。好吧,在幕后约束和用户定义的触发器可能会共享某些低级内核代码。但在我们谈论的层面上,它们是两个不同的东西。
如果您想禁用表上的所有外键,恐怕您需要使用类似这样的东西:
您可能希望将这种东西包装在用户定义的函数中,该函数将 TABLE_NAME 作为范围。此外,您还需要一个类似的函数来重新启用约束。
The syntax does disable triggers in Oracle:
However it won't do anything for foreign keys, or indeed any other constraint. That's because Oracle doesn't use triggers to enforce such things. Okay, under the covers constraints and user-defined triggers may share certain low-level kernel code. But at the level we're talking they are two different things.
If you want to disable all foreign keys on a table I'm afraid you'll need to use something like this:
This is the sort of thing you'll probably want to wrap in a user-defined function, which takes TABLE_NAME as a parameter. Also you'll need a similar function to re-enable the constraints.