Subject Re: Triggers to automagically add/modify/delete data in another table ?
Author Adam
--- In, Adriano <fadrianoc@...> wrote:
> Hi,
> i've this elementary problem.
> I've two table (table A and table B).
> When add/modify/delete data in table A i need to add/modify/delete
> (some data of table A) also in table B.
> When use access database i put in table B a field in which i insert
> the Unique ID of table A so that:
> 1) new data in table A: after insert new data (row) i detect Unique ID
> and add also data and ID in table B
> 2) modify data in table A: i detect the unique ID, find it in table B
> and modify data also in table B
> 3) deleta data in table A: i detect the unique ID, find it in table B
> and delete data also in table B
> With firebirs which is the best way to do that ?

It seems like a strange requirement, that information contained solely
in TableA is enough to correctly populate TableB. Are you sure TableB
should not simply be a view?

Not knowing the precise nature of the problem, and assuming the view
suggested above is not a possibility, then you would define the unique
ID as a foreign key with cascading deletes. This would handle the
delete problem.

The insert and update problem are simple triggers.

> Using a trigger ?
> How to retreive the Unique ID of table A after the insert of a new
row of data ?
> Some example is avaible for that scenario ?
> I use FB 2.x but cannot find the employee example database.

Given that you don't seem to be familiar with triggers in Firebird,
unless you require some features only available in FB 2, I would stick
with FB 1.5 until FB 2 is actually released.