Subject | Re: [ib-support] Re: Master-Detail constraint checking |
---|---|
Author | Doug Chamberlin |
Post date | 2003-04-28T19:38:19Z |
At 4/28/2003 01:56 PM (Monday), Alexander V.Nevsky wrote:
presented.
Your example works fine for maintaining a total field in a master record of
a field in all existing detail records.
The original problem was how to best enforce a condition that a collection
of detail records must have, such as the sum of all debit fields in those
detail records equaling the sum of all their credit fields, while inserts
and updates are being done to the collection. The condition should only be
checked at discrete times - not continuously - and, therefore, does not
match well with the available declarative (static) referential integrity
facilities.
My idea, and that of Marcos Vinicius Dufloth, was to add a field to the
master table which indicated when all of the detail records were complete.
A change to that field would indicate to a trigger that the sums should be
checked to see of the entire detail collection was "correct".
I had another idea since then. The triggers on the detail table operations
could always check the sums and post a value to a master field which
indicated whether the detail records were "correct". That way with ever
detail record operation the result would always be available and the master
record would always reflect the state of the entire detail record
collection. Once the final detail record was created/adjusted so that the
detail record set was "correct", the master record would then automatically
reflect that it was ready for further consideration.
All in all, the choice is an application-dependent one, I think.
>Or did I misunderstood subject of the discussion?I think you did present a solution to different problem than was originally
presented.
Your example works fine for maintaining a total field in a master record of
a field in all existing detail records.
The original problem was how to best enforce a condition that a collection
of detail records must have, such as the sum of all debit fields in those
detail records equaling the sum of all their credit fields, while inserts
and updates are being done to the collection. The condition should only be
checked at discrete times - not continuously - and, therefore, does not
match well with the available declarative (static) referential integrity
facilities.
My idea, and that of Marcos Vinicius Dufloth, was to add a field to the
master table which indicated when all of the detail records were complete.
A change to that field would indicate to a trigger that the sums should be
checked to see of the entire detail collection was "correct".
I had another idea since then. The triggers on the detail table operations
could always check the sums and post a value to a master field which
indicated whether the detail records were "correct". That way with ever
detail record operation the result would always be available and the master
record would always reflect the state of the entire detail record
collection. Once the final detail record was created/adjusted so that the
detail record set was "correct", the master record would then automatically
reflect that it was ready for further consideration.
All in all, the choice is an application-dependent one, I think.