Subject | Re: Maintain Summary Table with Database Trigger |
---|---|
Author | hvlad |
Post date | 2010-07-23T20:35:40Z |
--- In firebird-support@yahoogroups.com, "unordained" <unordained_00@...> wrote:
Regards,
Vlad
>Context variables are way better for such usage
> ---------- Original Message -----------
> From: "JackR" <jack@...>
> > Assuming that it is not a non-issue, is there a way to configure a
> > database trigger to do this update?
> ------- End of Original Message -------
>
> Yup.
>
> create trigger detail_changed for detail after insert or update or delete as
> begin
> -- in case you change master_id (move detail from one master to another)
> -- use both values. probably more efficient ways to do that.
> -- avoid updating records that have already been marked, fewer disk writes(?)
> update master set fix_me = 1 where id in (new.master_id, old.master_id) and
> fix_me is distinct from 1;
> end
>
> create trigger fix_master on transaction commit as
> begin
> for select ... from master where fix_me = 1 into ... as cursor cur do
> begin
> update master set ... fix_me = 0 where current of cur;
> end
> end
>
> This will result in record locks, but if you're updating the master no matter
> what, using a temp table (rather than a "fix_me" field) won't change that.
Regards,
Vlad