問題:
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.通常,開發人員甚至不會考慮查看是否有觸發器。
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.另一方面,如果在數據庫中創建新的FOO
必鬚髮生邏輯,那麼放置它的最簡單的地方是 FOO 表上的插入觸發器。
The only time we're using triggers is for really simple things like setting the ModifiedDate
.我們使用觸發器的唯一時間是非常簡單的事情,比如設置ModifiedDate
。
解決方案:
參考一: https://en.stackoom.com/question/1vkS參考二: https://stackoom.com/question/1vkS