我需要将一个表中的插入/更新/删除操作映射到另一个表。 例如,必须将TABLEA的插入复制到桌面中,更新到应用于TableB的Tablea,并将Tablea删除应用于TableB。 它如同简单,除了桌面有1个常量值的额外列,所以需要非常简单的触发器。

我不确定它是否最好写入3个单独的触发器,或者有一个触发器,也可以进行所有操作。

这适用于3个数据库:Sybase ASE,MSSQL和Oracle,我想将其保持类似的解决方案(所以对于所有数据库,或者所有数据库都是如此)。

是一个偏好的问题,有3个触发器与1,或者对任何一种解决方案有实际益处吗?

有帮助吗?

解决方案

Assuming that you actually need a trigger and that table B cannot simply be defined as a view on top of table A or that table B cannot just be defined with a foreign key that references a row in A along with the constant, that A cannot be redefined to add the additional column (potentially with a default value of the constant), one trigger at least lets you keep all the related logic in one place rather than having multiple places that need to be updated when you do something like add a new column to A. But I would be extremely wary of any architecture that involved having two different tables reflecting essentially the same data in both. That violates normalization, it adds to the system's I/O workload, and it makes the whole system more complex.

其他提示

There's no efficiency to be gained by separating the triggers, other than the loss of efficiency of the trigger execution itself, when trying to determine what the action on Table A was.

IE 3 separate triggers can employ no validation logic to determine what just occurred on Table A, since the trigger being fired itself can behave in a bubble because it knows since it's firing, it was due to single action.

Whereas a 3-in-1 trigger, you must check the status of the virtual deleted and inserted tables and derive the action each and every time it's fired.

If you're not worried about the (admittedly small) performance impact of deriving the "action", or maybe don't even need to know in Table B the "action" that just occurred on Aable A...then I think 1 is perfectly fine.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top