Subject Re: Master-Detail constraint checking
Author Alexander V.Nevsky
--- In ib-support@yahoogroups.com, "sugi" <truesaint@c...> wrote:
> Dear all,
>
> Let's assume a classic accounting database where you have a
> master-detail relationship between JOURNAL and JOURNALDETAIL. One of
the
> rules says that for every JOURNAL, the sum of (JournalDetail.debit)
must
> be equal to the sum of (JournalDetail.credit). But normally this
rule is
> only satisfied by the end of the posting sequence. Here's a sample
> posting sequence (in pseudocode):

Dear all :) I can't understand why do you need trigger on commit
here. Let's say we have relationship invoice - positions,
read_commited transactions and triggers on Invoice_Positions like

Insert

Update Invoices Set Sum_Positions=Sum_Positions+New.Cost
Where ID=New.Invoice_ID

Update

Update Invoices Set Sum_Positions=Sum_Positions+New.Cost-Old.Cost
Where ID=New.Invoice_ID

Delete

Update Invoices Set Sum_Positions=Sum_Positions-Old.Cost
Where ID=New.Invoice_ID

if transaction mode is wait, we'll not get conflicts at all. Some
delay, maybe. In some cases cashed updates can be used to minimize
this delay by shortening frequency of data change attempts on server
side, in some - make each position changing in own short transaction.
Or did I misunderstood subject of the discussion?

Best regards, Alexander.