/******************************************************************************/
/****              Generated by IBExpert 04/08/2023 08:25:26               ****/
/******************************************************************************/

/******************************************************************************/
/****     Following SET SQL DIALECT is just for the Database Comparer      ****/
/******************************************************************************/


/******************************************************************************/
/****                                Tables                                ****/
/******************************************************************************/


CREATE GENERATOR GEN_CENTRAL_MINERADORA_ATUAL_ID;

CREATE TABLE CENTRAL_MINERADORA_ATUALIZAR (
    CODIGO                          DOM_CODIGO NOT NULL /* DOM_CODIGO = INTEGER */,
    ANDAMENTOS                      DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    ASSUNTOS                        DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    CAUSAS                          DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    DADOS_DAS_CDAS                  DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    DATA_DISTRIBUICAO               DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    FORO                            DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    NATUREZA                        DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    NUMERO_ORDEM_VARA               DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    PARTES_E_CLASSIFICACAO          DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    TIPO_PROCESSO                   DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    TRAMITE                         DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    VALOR_PROCESSO                  DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    PROCURADOR_ULTIMO_DOC_ASSINADO  DOM_CODIGO DEFAULT 0 /* DOM_CODIGO = INTEGER */,
    COD_USUARIO                     DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    DATA_INC                        DOM_DATA_HORA /* DOM_DATA_HORA = DATE */
);



/******************************************************************************/
/****                             Primary keys                             ****/
/******************************************************************************/

ALTER TABLE CENTRAL_MINERADORA_ATUALIZAR ADD CONSTRAINT PK_CENTRAL_MINERADORA_ATUALIZAR PRIMARY KEY (CODIGO);


/******************************************************************************/
/****                               Triggers                               ****/
/******************************************************************************/



SET TERM ^ ;



/******************************************************************************/
/****                         Triggers for tables                          ****/
/******************************************************************************/



/* Trigger: CENTRAL_MINERADORA_ATU_CODIGO */
CREATE OR ALTER TRIGGER CENTRAL_MINERADORA_ATU_CODIGO FOR CENTRAL_MINERADORA_ATUALIZAR
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.CODIGO IS NULL) THEN
    NEW.CODIGO = GEN_ID(GEN_CENTRAL_MINERADORA_ATUAL_ID,1);
END
^

/* Trigger: CENTRAL_MINERADORA_ATU_DATA_INC */
CREATE OR ALTER TRIGGER CENTRAL_MINERADORA_ATU_DATA_INC FOR CENTRAL_MINERADORA_ATUALIZAR
ACTIVE BEFORE INSERT POSITION 2
AS
BEGIN
  NEW.DATA_INC = CURRENT_TIMESTAMP;
END
^

/* Trigger: CENTRAL_MINERADORA_ATU_USUARIO */
CREATE OR ALTER TRIGGER CENTRAL_MINERADORA_ATU_USUARIO FOR CENTRAL_MINERADORA_ATUALIZAR
ACTIVE BEFORE INSERT POSITION 1
AS
DECLARE VARIABLE I_TEMP INTEGER;
BEGIN
  SELECT COD_USUARIO
  FROM FUNCAO_COD_USUARIO
  INTO :I_TEMP;
  NEW.COD_USUARIO = :I_TEMP;
END
^
SET TERM ; ^