Subject | Re: [firebird-support] Master-Detal and trigger |
---|---|
Author | Nando Dessena |
Post date | 2004-11-24T12:02:52Z |
Primoz,
P> Now I want to make a trigger, which will set my A1_A_KEY automaticaly to
P> coresponding A_KEY value from master table, when I insert new record to
P> detail table.
how would the trigger know what's the "corresponding" master record,
if the key is missing? You need to pass the master key in the insert
statement, because that's how you say to the database what's the
master record of which you are inserting a detail record.
P> Until now, I used dataset's after insert event to set the coresponding
P> value, but I think, trigger should be used for that purpose, right ?
Wrong. Your current approach is just fine. If you need something to
improve, I'd suggest you remove all those quoted identifiers (") and
restructure your database to avoid composite primary keys instead.
Unless that was just an example.
Ciao
--
Nando Dessena
http://www.flamerobin.org
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================
P> Now I want to make a trigger, which will set my A1_A_KEY automaticaly to
P> coresponding A_KEY value from master table, when I insert new record to
P> detail table.
how would the trigger know what's the "corresponding" master record,
if the key is missing? You need to pass the master key in the insert
statement, because that's how you say to the database what's the
master record of which you are inserting a detail record.
P> Until now, I used dataset's after insert event to set the coresponding
P> value, but I think, trigger should be used for that purpose, right ?
Wrong. Your current approach is just fine. If you need something to
improve, I'd suggest you remove all those quoted identifiers (") and
restructure your database to avoid composite primary keys instead.
Unless that was just an example.
Ciao
--
Nando Dessena
http://www.flamerobin.org
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================