Subject | RE: [firebird-support] some SQL Question |
---|---|
Author | Thomas Steinmaurer |
Post date | 2003-10-30T08:52:06Z |
Hi Richard,
table the trigger fires.
SET TERM ^^ ;
CREATE TRIGGER TRI_SALES_UPDATECATEGORY_ID FOR SALES
ACTIVE BEFORE INSERT POSITION 0 AS
DECLARE VARIABLE ACATEGORY_ID INTEGER;
begin
SELECT CATEGORY_ID FROM OPTICIAN WHERE ID = NEW.OPTICIAN_ID INTO :ACATEGORY_ID;
NEW.CATEGORY_ID = ACATEGORY_ID;
end
^^
SET TERM ; ^^
HTH,
Thomas Steinmaurer
The IB LogManager Product Family
Logging/Auditing Suite for InterBase and Firebird
http://www.iblogmanager.com
> Im now working with firebird for a weak or two, and Now im at an intrestingUse an BEFORE INSERT trigger if you want to set a column for the
> part of the database..... triggers...
>
> And I can't succeed getting this right.
>
> Table 1
>
> OPTICIAN
> ID,
> NAME,
> CATEGORY_ID
>
> Table 2
>
> SALES
> ID,
> OPTICIAN_ID,
> CATEGORY_ID
>
> I would like after insert on SALES
>
> Select category_id from OPTICIAN where ID = x
>
> Update SALES set CATEGORY_ID = (selected category_id)
table the trigger fires.
SET TERM ^^ ;
CREATE TRIGGER TRI_SALES_UPDATECATEGORY_ID FOR SALES
ACTIVE BEFORE INSERT POSITION 0 AS
DECLARE VARIABLE ACATEGORY_ID INTEGER;
begin
SELECT CATEGORY_ID FROM OPTICIAN WHERE ID = NEW.OPTICIAN_ID INTO :ACATEGORY_ID;
NEW.CATEGORY_ID = ACATEGORY_ID;
end
^^
SET TERM ; ^^
HTH,
Thomas Steinmaurer
The IB LogManager Product Family
Logging/Auditing Suite for InterBase and Firebird
http://www.iblogmanager.com