Ver Mensaje Individual
  #10  
Antiguo 30-11-2011
Avatar de guillotmarc
guillotmarc guillotmarc is offline
Miembro
 
Registrado: may 2003
Ubicación: Huelva
Posts: 2.638
Reputación: 24
guillotmarc Va por buen camino
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
__________________
Marc Guillot (Hi ha 10 tipus de persones, els que saben binari i els que no).
Responder Con Cita