CREATE INDEX ITBWORKFLOW_ITEM_CAMPO_06
ON TBWORKFLOW_ITEM_CAMPO (TIPO);

CREATE INDEX ITBWORKFLOW_ITEM_CAMPO_07
ON TBWORKFLOW_ITEM_CAMPO (ROTULO);

CREATE INDEX ITBWORKFLOW_ITEM_CAMPO_08
ON TBWORKFLOW_ITEM_CAMPO (WORKFLOW_TAREFA_CAMPO_ID);

CREATE INDEX ITBWORKFLOW_ITEM_HISTORICO_01
ON TBWORKFLOW_ITEM_HISTORICO (WORKFLOW_ITEM_TAREFA_ID);

CREATE INDEX ITBWORKFLOW_ITEM_HISTORICO_02
ON TBWORKFLOW_ITEM_HISTORICO (WORKFLOW_ITEM_ID);

CREATE INDEX ITBWORKFLOW_ITEM_HISTORICO_03
ON TBWORKFLOW_ITEM_HISTORICO (HISTORICO);

CREATE INDEX ITBWORKFLOW_ITEM_HISTORICO_04
ON TBWORKFLOW_ITEM_HISTORICO (USUARIO_ID);

CREATE INDEX ITBWORKFLOW_ITEM_HISTORICO_05
ON TBWORKFLOW_ITEM_HISTORICO (DATAHORA);

CREATE INDEX ITBWORKFLOW_ITEM_DESTINATAR_02
ON TBWORKFLOW_ITEM_DESTINATARIO (WORKFLOW_ID);

CREATE INDEX ITBWORKFLOW_ITEM_DESTINATAR_03
ON TBWORKFLOW_ITEM_DESTINATARIO (WORKFLOW_ITEM_ID);

CREATE INDEX ITBWORKFLOW_ITEM_DESTINATAR_04
ON TBWORKFLOW_ITEM_DESTINATARIO (WORKFLOW_ITEM_TAREFA_ID);

CREATE INDEX ITBWORKFLOW_ITEM_DESTINATAR_05
ON TBWORKFLOW_ITEM_DESTINATARIO (USUARIO_ID);

CREATE INDEX ITBWORKFLOW_ITEM_DESTINATAR_06
ON TBWORKFLOW_ITEM_DESTINATARIO (NOTIFICACAO);

CREATE INDEX ITBWORKFLOW_ITEM_TAREFA_03
ON TBWORKFLOW_ITEM_TAREFA (WORKFLOW_ID);

CREATE INDEX ITBWORKFLOW_ITEM_TAREFA_04
ON TBWORKFLOW_ITEM_TAREFA (WORKFLOW_ITEM_ID);

CREATE INDEX ITBWORKFLOW_ITEM_TAREFA_05
ON TBWORKFLOW_ITEM_TAREFA (ORDEM);

CREATE INDEX ITBWORKFLOW_ITEM_TAREFA_06
ON TBWORKFLOW_ITEM_TAREFA (SEQUENCIA);

CREATE INDEX ITBWORKFLOW_ITEM_TAREFA_07
ON TBWORKFLOW_ITEM_TAREFA (WORKFLOW_TAREFA_MODELO_ID);

CREATE INDEX ITBWORKFLOW_ITEM_TAREFA_08
ON TBWORKFLOW_ITEM_TAREFA (TITULO);

CREATE INDEX ITBWORKFLOW_DEPENDENCIA_04
ON TBWORKFLOW_DEPENDENCIA (USUARIO_ID);

CREATE INDEX ITBWORKFLOW_DESTINATARIO_03
ON TBWORKFLOW_DESTINATARIO (USUARIO_ID);

CREATE INDEX ITBWORKFLOW_DESTINATARIO_04
ON TBWORKFLOW_DESTINATARIO (NOTIFICACAO);

CREATE OR ALTER TRIGGER TTBWORKFLOW_B03U FOR TBWORKFLOW
ACTIVE BEFORE UPDATE POSITION 0
AS
DECLARE VARIABLE WORKFLOW_ITEM INTEGER;
BEGIN
  IF(OLD.TIPO <> NEW.TIPO)THEN
  BEGIN
     WORKFLOW_ITEM = COALESCE((SELECT FIRST 1 B.ID FROM TBWORKFLOW_ITEM B WHERE B.WORKFLOW_ID = NEW.ID),0);
     IF(:WORKFLOW_ITEM > 0)THEN
     BEGIN
       EXCEPTION "..." 'O TIPO DO MODELO JA ESTA SENDO UTILIZADO EM WORKFLOWS GERADOS, OPERACAO CANCELADA!.';
     END
  END
END;

UPDATE TBMENU SET DESCRICAO = 'CADASTRO DE MODELOS DE WORKFLOW' WHERE CONTROLE = 29020;

DELETE FROM TBRELATORIO_WEB WHERE ID = 78 AND UPPER(DESCRICAO) = 'ACOMPANHAMENTO DE WORKFLOW' AND CODIGO = 28078;

	