数据库触发了邪恶吗? [英] Are database triggers evil?

查看:71
本文介绍了数据库触发了邪恶吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库触发了一个坏主意吗?

Are database triggers a bad idea?

根据我的经验,它们是邪恶的,因为它们会导致令人惊讶的副作用,并且难以调试(尤其是当触发另一个)。通常,开发人员甚至都不考虑是否存在触发器。

In my experience they are evil, because they can result in surprising side effects, and are difficult to debug (especially when one trigger fires another). Often developers do not even think of looking if there is a trigger.

另一方面,似乎您是否有必须在每次出现新的<$ c时都要发生的逻辑$ c> FOO 在数据库中创建,然后放到最简单的地方是FOO表上的插入触发器。

On the other hand, it seems like if you have logic that must occur evertime a new FOO is created in the database then the most foolproof place to put it is an insert trigger on the FOO table.

唯一我们使用触发器的时间是用于非常简单的事情,例如设置 ModifiedDate

The only time we're using triggers is for really simple things like setting the ModifiedDate.

推荐答案

触发器的主要问题是


  • 它们完全是全局的-无论表活动的上下文如何,它们都适用;

  • 它们是隐形的;很容易忘记他们在那里,直到他们以意想不到的(非常神秘的)后果伤害了您。

这只是意味着他们需要在适当情况下谨慎使用;根据我的经验,这仅限于关系完整性问题(有时粒度要比声明性要好);并且通常不用于商业或交易目的。 YMMV。

This just means they need to be carefully used for the proper circumstances; which in my experience is limited to relational integrity issues (sometimes with finer granularity than you can get declaratively); and usually not for business or transactional purposes. YMMV.

这篇关于数据库触发了邪恶吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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