Solved
Add a default constraint on (trace) columns
Is it possible to add a 'DEFAULT' constraint to columns via the TSF? Currently we fill trace columns via insert and update triggers but this results in unwanted trigger actions.
The insert trigger will update the same table and thereby triggers the update trigger. Which in return executes the whole update trigger. (See code below)
We have multiple places where this trigger nesting causes errors or wrong results.
If we could add a DEFAULT constraint to the insert columns the code of the insert trigger won't be necessary anymore.
The insert trigger will update the same table and thereby triggers the update trigger. Which in return executes the whole update trigger. (See code below)
We have multiple places where this trigger nesting causes errors or wrong results.
If we could add a DEFAULT constraint to the insert columns the code of the insert trigger won't be necessary anymore.
Best answer by Jasper
K.Bakkenes wrote:
Hi Jasper,
for example: The table product has a product_id as PK and resource_id as FK. In the insert trigger of product a record must be inserted into the table resource. After the resource is created the resource_id column must be updated to the product table. In the update trigger of product a gross price must be created using the resource_id from the product table.
If the update on the trace columns is prior to the insert (and update) of the resource_id column then the update trigger will fail because resource_id will be empty while creating a gross price.
for example: The table product has a product_id as PK and resource_id as FK. In the insert trigger of product a record must be inserted into the table resource. After the resource is created the resource_id column must be updated to the product table. In the update trigger of product a gross price must be created using the resource_id from the product table.
If the update on the trace columns is prior to the insert (and update) of the resource_id column then the update trigger will fail because resource_id will be empty while creating a gross price.
You can of course solve this by taking a possible empty resource_id into account in the update trigger, but in general we always recommend doing updates from within a trigger on the same table at the end of the trigger to prevent any side-effects.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.