Subject | Master-Detal and trigger |
---|---|
Author | Planles |
Post date | 2004-11-24T11:53:51Z |
Hello,
I'm trying to get some knowlegde about triggers in FB (1.5).
I've read some stuff about trigger in doc and Helen's book, but haven't got
it working, so I'm asking for your help.
I have a very basic master-detail relationship created with following
script:
CREATE TABLE "TABLE_A"
(
"A_KEY" VARCHAR(10) NOT NULL,
"A_DESC" VARCHAR(30) ,
"A_VAL" FLOAT,
PRIMARY KEY ("A_KEY")
);
CREATE TABLE "TABLE_A1"
(
"A1_A_KEY" VARCHAR(10) NOT NULL,
"A1_KEY" VARCHAR(10) NOT NULL,
"A1_VAL" FLOAT,
PRIMARY KEY ("A1_A_KEY", "A1_KEY")
);
ALTER TABLE "TABLE_A1" ADD FOREIGN KEY ("A1_A_KEY") REFERENCES TABLE_A
("A_KEY") ON UPDATE CASCADE ON DELETE CASCADE;
Now I want to make a trigger, which will set my A1_A_KEY automaticaly to
coresponding A_KEY value from master table, when I insert new record to
detail table.
I tried this:
CREATE TRIGGER "SET_FK_VAL" FOR "TABLE_A1"
ACTIVE BEFORE INSERT POSITION 0
AS
begin
NEW.A1_A_KEY = :A_KEY;
end
but there was complaints about invalid command from my admin tool already.
Until now, I used dataset's after insert event to set the coresponding
value, but I think, trigger should be used for that purpose, right ?
Thanks in advance for your help.
Regards,
Primoz
I'm trying to get some knowlegde about triggers in FB (1.5).
I've read some stuff about trigger in doc and Helen's book, but haven't got
it working, so I'm asking for your help.
I have a very basic master-detail relationship created with following
script:
CREATE TABLE "TABLE_A"
(
"A_KEY" VARCHAR(10) NOT NULL,
"A_DESC" VARCHAR(30) ,
"A_VAL" FLOAT,
PRIMARY KEY ("A_KEY")
);
CREATE TABLE "TABLE_A1"
(
"A1_A_KEY" VARCHAR(10) NOT NULL,
"A1_KEY" VARCHAR(10) NOT NULL,
"A1_VAL" FLOAT,
PRIMARY KEY ("A1_A_KEY", "A1_KEY")
);
ALTER TABLE "TABLE_A1" ADD FOREIGN KEY ("A1_A_KEY") REFERENCES TABLE_A
("A_KEY") ON UPDATE CASCADE ON DELETE CASCADE;
Now I want to make a trigger, which will set my A1_A_KEY automaticaly to
coresponding A_KEY value from master table, when I insert new record to
detail table.
I tried this:
CREATE TRIGGER "SET_FK_VAL" FOR "TABLE_A1"
ACTIVE BEFORE INSERT POSITION 0
AS
begin
NEW.A1_A_KEY = :A_KEY;
end
but there was complaints about invalid command from my admin tool already.
Until now, I used dataset's after insert event to set the coresponding
value, but I think, trigger should be used for that purpose, right ?
Thanks in advance for your help.
Regards,
Primoz