View Single Post

   
  #2 (permalink)  
Old 02-24-2008, 02:52 PM
Tony Andrews
 
Posts: n/a
Default Re: Deferred trigger ..?

Randi W wrote:
> These will be treated as two statements, so what I would really like is if
> the after-statment-trigger could be fired at COMMIT time. A similar thing
> can be done by using 'deferred'-setting for constraints.
>
> Is it possible?


No, but what you can do is use a combination of triggers and a deferred
CHECK constraint. For example, you could add a column called
NumCurrentAddresses to the Persons table, with a deferred CHECK
constraint to ensure it is <= 1. Then use triggers on the Address
tables to update the new column after inserts, updates and deletes.

Another possible approach is to create a materialized view that selects
only the Address rows where IsCurrent=1, and then add a deferred unique
constraint on the MV's person_id column.

Reply With Quote