/******************************************************************************/
/****              Generated by IBExpert 09/08/2023 12:07:04               ****/
/******************************************************************************/

/******************************************************************************/
/****     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 /* DOM_CODIGO = INTEGER */,
    FORO         DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    CONTENCIOSO  DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    TRAMITE      DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    CAUSA        DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    NRO_ORDEM    DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    VIRTUAL      DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    VALOR_PROC   DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    DATA_DISTR   DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    OBS          DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    CDAS         DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    ADV_INT      DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    CLASSIF      DOM_CODIGO /* 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 ; ^
