TRIGGER或MULTI Insert [英] TRIGGER or MULTI Insert

查看:121
本文介绍了TRIGGER或MULTI Insert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我必须以另一种方式问我的问题。
在事务数据库中,建议使用以下哪种情况:

I think I have to ask my question in another way. At transactional database which of the following case has been recommended:


  1. 编写多个或2个插入查询以保存程序日志

  2. 在DB上插入用于保存程序日志的写入触发器,对DB有更大的压力。

  1. writing multi or 2 insert query for saving log of program on DB that has more pressure on server .
  2. writing trigger after inserting for saving log of program on DB that has more pressure on DB.

感谢您的关注。


推荐答案

到DB的插入只会发生从你的应用程序结束,那么我会通过创建一个过程的第一个选项,并包括 INSERT 语句在 TRANSACTION 块。这将确保原子操作。

If you are sure that the insert to the DB will happen only from your application end then I would go for the first option by creating a procedure and include both the INSERT statement in a TRANSACTION block. which will make sure atomic operation.

但是,如果有可能通过adhoc查询或通过第三方ETL工具插入数据库可能会发生,那么你没有其他选项比执行日志插入操作(第二个选项)有一个触发器 AFTER INSERT TRIGGER ,因为没有办法调用另一个 INSERT 语句自动或显式。

But, in case there are possibilities that insert to the DB may happen through adhoc query or through third party ETL tool then you have no other option than having a trigger AFTER INSERT TRIGGER to perform the log insert operation (2nd option) since there is no way to call the other INSERT statement automatically or explicitly.

这篇关于TRIGGER或MULTI Insert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆