SET TERM ^ ;

CREATE OR ALTER trigger ttbusuario_b02d for tbusuario
active before delete position 1
AS
BEGIN
   IF(OLD.CODIGO > 0) THEN
   BEGIN
      DELETE FROM TBUSUARIO_BI              WHERE USUARIO_ID = OLD.CODIGO;
      DELETE FROM TBUSUARIO_CCUSTO          WHERE USUARIO_ID = OLD.CODIGO;
      DELETE FROM TBUSUARIO_ESTABELECIMENTO WHERE USUARIO_CODIGO = OLD.CODIGO;
      DELETE FROM TBUSUARIO_FAMILIA         WHERE USUARIO_ID = OLD.CODIGO;
      DELETE FROM TBUSUARIO_LEMBRETE        WHERE USUARIO_ID = OLD.CODIGO;
      DELETE FROM TBUSUARIO_REPRESENTANTE   WHERE USUARIO_CODIGO = OLD.CODIGO;
      DELETE FROM TBUSUARIO_ESTABELECIMENTO WHERE USUARIO_CODIGO = OLD.CODIGO;
      DELETE FROM TBMENU_USUARIO            WHERE USUARIO_CODIGO = OLD.CODIGO;
      DELETE FROM TBUSUARIO_LOCALIZACAO     WHERE USUARIO_ID = OLD.CODIGO;
      DELETE FROM TBCONSUMO_REQ_PERMISSAO   WHERE USUARIO_ID = OLD.CODIGO;
      DELETE FROM TBRELATORIO_WEB_USUARIO   WHERE USUARIO_ID = OLD.CODIGO;
   END
END
^

SET TERM ; ^

