即使应用程序崩溃,触发器也会保持原子性吗
我遇到的情况是,我有 2 个表,可以在其中执行插入、更新、删除操作。我引入了一个表audit_trail 来维护这两个表的更改日志。现在要在audit_trail 表中输入值,我已经编写了插入语句在任何一个表上进行任何更新、删除或插入之后。现在,如果其中一个表发生修改并且应用程序崩溃,那么根据我的方法,审核表插入将不会发生。所以我想知道我是否编写了一个触发器在此表上插入、更新或删除后的条件下,即使应用程序崩溃,这也会导致插入审计。DBMS 是 Oracle
I have a situation where I have 2 tables in which I can do Insert,Update,Delete.I'm introducing a table audit_trail to maintain a log of changes of this two tables.Now to enter values in audit_trail table I have written insert statements after any Update,Delete or Insert on either of the table.Now if an modification happened on one of the table and the application crashed then based on my method the Audit table insert will not happen.So I wanted to know if I write a trigger on the condition after insert or update or delete on this table then will this lead to an insert into audit even if the application crashes.DBMS is Oracle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 AUTONOMOUS_TRANSACTION 编译指示。这允许我们在离散事务中发出 SQL,这意味着提交内容不会影响更广泛的事务。因此,即使数据库在用户发出显式提交(或其他)之前崩溃,您的审核消息也会被提交。
显然我不知道你想记录什么数据,但是编写一个像这样的过程并从触发器中调用它:
This is one of the few, possibly the only, valid uses for the AUTONOMOUS_TRANSACTION pragma. This allows us to issue SQL in a discrete transaction, which means that stuff gets committed without affecting the wider transaction. Consequently your audit messages will be committed even if the database crashes before the user issues an explicit commit (or whatever).
Obviously I don't know what data you want to log, but write a procedure like this and call it from your triggers:
您需要将插入移动到存储过程中,并从审计跟踪触发器中调用它。
在存储过程内部启用“自主事务”,然后您可以在存储过程内部提交,而不会影响触发触发器的“外部”事务。
详细信息请参阅手册:
http://download.oracle.com/docs /cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1514
You need to move your insert into a stored procedure and call that from within the audit trail trigger.
Inside the stored procedure enable "autonomous transaction", and then you can commit inside the stored procedure without affecting the "outer" transaction that fired the trigger.
For details see the manual:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1514