Hola.
Te recomiendo que leas este libro (ya tiene unos buenos años, para la utilización de las bases de datos ha cambiado poco desde entonces).
http://www.marteens.com/pdfs/TheDarkSideOfDelphi6.pdf
Aquí también encontrarás mucha información de interés.
http://www.firebird.com.mx
en concreto deberías leer este artículo
http://www.firebird.com.mx/modules/A...php?storyid=28
Respecto a tu trigger, va a ser algo de este estilo :
Código SQL
[-]
SET TERM ^ ;
CREATE TRIGGER RECALCULAR_STOCK for DETALLE_P
active after insert or update or delete position 0
AS
declare variable ID_ARTICULO integer;
begin
IF (deleting) THEN ID_ARTICULO = old.CODIGO;
ELSE ID_ARTICULO = new.CODIGO;
UPDATE ARTICULO SET STOCK = -1 * (SELECT SUM(CANTIDAD_ARTICULO) FROM DETALLE_P WHERE CODIGO = :ID_ARTICULO)
WHERE ID_ARTICULO = (:ID_ARTICULO);
end
^
SET TERM ; ^
Saludos