Subject Re: [firebird-support] table names as variables...
Author Helen Borrie
At 12:21 PM 26/11/2003 +1100, you wrote:
>Hello Everyone,
>
>Just wondering how I would achieve this in firebird / ib? A record in
>G_LEVEL has just been deleted (primary key is level_def_num), and I want to
>delete the contents of another table which has entries linked by
>level_def_num. The table name to have the entries deleted from is stored
>in table G_TOPICS. Is it possible to embed the table name in such a way in
>my delete statement?
>
>====
>
>CREATE TRIGGER TRG_G_LEVEL_DELETE FOR G_LEVEL ACTIVE
> AFTER DELETE POSITION 0
> AS
> DECLARE VARIABLE TOPIC_TABLE VARCHAR(12);
> BEGIN
> /* Now delete the level data from the topic specific database */
> SELECT DATABASE_NAME FROM G_TOPICS WHERE G_TOPICS.topic_num =
>old.topic_num INTO :topic_table;
> DELETE FROM :topic_table WHERE level_def_num = old.level_def_num;
> END
>
>====

In Interbase or Fb 1, no. In Fb 1.5, yes, though not using your
syntax. What you can do in 1.5 is run an EXECUTE STATEMENT statement
inside your PSQL code, which is an "executable string", a statement which
you build up and pass as the argument to EXECUTE STATEMENT, then execute.

This isn't a very robust way to maintain RI but I guess with this
dependency structure you don't have any choice.

heLen