/******************************************************************************/
/****              Generated by IBExpert 19/02/2021 07:34:40               ****/
/******************************************************************************/

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



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


CREATE GENERATOR GTBARQUIVOS_MDF;

CREATE TABLE TBARQUIVOS_MDF (
    ID          INTEGER NOT NULL,
    MDF_ID      INTEGER,
    CONTEUDO    BLOB SUB_TYPE 0 SEGMENT SIZE 80,
    EXTENSAO    VARCHAR(10),
    TAMANHO     INTEGER,
    ARQUIVO     VARCHAR(200),
    USUARIO_ID  INTEGER,
    PRINCIPAL   INTEGER,
    DATAHORA    TIMESTAMP DEFAULT 'NOW'
);




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

ALTER TABLE TBARQUIVOS_MDF ADD CONSTRAINT PK_TBARQUIVOS_MDF PRIMARY KEY (ID);


/******************************************************************************/
/****                               Indices                                ****/
/******************************************************************************/

CREATE INDEX TBARQUIVOS_MDF_01 ON TBARQUIVOS_MDF (MDF_ID);
CREATE INDEX TBARQUIVOS_MDF_02 ON TBARQUIVOS_MDF (EXTENSAO);
CREATE INDEX TBARQUIVOS_MDF_03 ON TBARQUIVOS_MDF (USUARIO_ID);
CREATE INDEX TBARQUIVOS_MDF_04 ON TBARQUIVOS_MDF (PRINCIPAL);
CREATE INDEX TBARQUIVOS_MDF_05 ON TBARQUIVOS_MDF (ARQUIVO);


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



SET TERM ^ ;



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



/* Trigger: TBARQUIVOS_MDF_B01I */
CREATE OR ALTER TRIGGER TBARQUIVOS_MDF_B01I FOR TBARQUIVOS_MDF
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
    NEW.ID = GEN_ID(GTBARQUIVOS_MDF,1);
END
^

SET TERM ; ^



/******************************************************************************/
/****                              Privileges                              ****/
/******************************************************************************/


/* Privileges of users */
GRANT ALL ON TBARQUIVOS_MDF TO GC WITH GRANT OPTION;
GRANT SELECT ON MON$ATTACHMENTS TO PUBLIC;
GRANT SELECT ON MON$CALL_STACK TO PUBLIC;
GRANT SELECT ON MON$CONTEXT_VARIABLES TO PUBLIC;
GRANT SELECT ON MON$DATABASE TO PUBLIC;
GRANT SELECT ON MON$IO_STATS TO PUBLIC;
GRANT SELECT ON MON$MEMORY_USAGE TO PUBLIC;
GRANT SELECT ON MON$RECORD_STATS TO PUBLIC;
GRANT SELECT ON MON$STATEMENTS TO PUBLIC;
GRANT SELECT ON MON$TABLE_STATS TO PUBLIC;
GRANT SELECT ON MON$TRANSACTIONS TO PUBLIC;