ALTER TABLE TBWORKFLOW_CAMPO
ADD STATUS VARCHAR(1) CHARACTER SET UTF8 
DEFAULT '1' 
COLLATE UTF8;

CREATE OR ALTER TRIGGER TTBWORKFLOW_CAMPO_B02D FOR TBWORKFLOW_CAMPO
ACTIVE BEFORE DELETE POSITION 1
AS
declare variable WORKFLOW_ITEM_ID   INTEGER;
declare variable WORKFLOW_DESCRICAO VARCHAR(200);
begin
   WORKFLOW_ITEM_ID   = COALESCE((SELECT FIRST 1 H.ID
                                      FROM TBWORKFLOW_ITEM_CAMPO  T,
                                           TBWORKFLOW_ITEM_TAREFA G,
                                           TBWORKFLOW_TAREFA      H
                                       WHERE t.WORKFLOW_TAREFA_CAMPO_ID = OLD.ID
                                         AND G.WORKFLOW_ITEM_ID         = T.WORKFLOW_ITEM_ID
                                         AND H.ID                       = G.WORKFLOW_TAREFA_MODELO_ID
                                    ), 0);

   WORKFLOW_DESCRICAO = COALESCE((SELECT FIRST 1 H.TITULO
                                      FROM TBWORKFLOW_ITEM_CAMPO  T,
                                           TBWORKFLOW_ITEM_TAREFA G,
                                           TBWORKFLOW_TAREFA      H
                                       WHERE t.WORKFLOW_TAREFA_CAMPO_ID = OLD.ID
                                         AND G.WORKFLOW_ITEM_ID         = T.WORKFLOW_ITEM_ID
                                         AND H.ID                       = G.WORKFLOW_TAREFA_MODELO_ID

                                    ),'');

   IF(:WORKFLOW_ITEM_ID > 0)THEN
   BEGIN
       EXCEPTION "..." ' CAMPO: '||COALESCE(OLD.ROTULO,'')||', NA TAREFA: '||:WORKFLOW_DESCRICAO||' ESTA SENDO UTILIZADO EM WORKFLOWS, OPERAÇÃO CANCELADA!';
   END
end;