0

我在 oracle 上的触发器有问题。

我有类似的东西:

 Project
 -------
 currentProgress
 plannedLoads
 currentLoads


Step
----
currentProgress
plannedLoads
currentLoads


Task
----
currentProgress
plannedLoads
currentLoads

项目由 Step 组成,Step 由 Task 组成。

currentProgress 总是 = currentLoads/plannedLoads。

我在插入任务之前有一个触发器,以在插入、更新或删除时改进 Step currentLoads,并在 Step currentLoads 上另一个触发器以改进 Project currentLoads。

因此,如果我更新 Task 会调用两个触发器,一个用于更新 Step,然后一个用于 Project。

例如,当我更新 Step 时,我会更新它的 currentLoad。

问题是当我删除一个项目时。我还必须删除与之相关的步骤和任务。因此,调用了 Task 和 Step on delete 的触发器,调用了 Project 上的触发器。

我不确定我是否清楚。如果没有,请询​​问我的详细信息。

谢谢你的帮助。

4

1 回答 1

1

This does not sound like an ideal scenario for triggers - they're better off used for additional validation (i.e. things that cannot be accomplished with constraints, not instead of constraints) / logging / sanity checks, etc. rather than application logic.

In addition, I would only use triggers for validation sparingly and as a complement to constraints and application validation.

I would strongly suggest moving the functionality for maintaining these records into a PL/SQL procedure, and invoke that instead of issuing DML statements against the tables directly. That way, you stay in control.

于 2013-06-16T08:22:08.850 回答