CREATE TABLE TBNF_LOGS (
    ID INTEGER NOT NULL,
    NF_ID INTEGER,
    ORIGEM VARCHAR(10),
    "LOG" BLOB SUB_TYPE 1 SEGMENT SIZE 80);

ALTER TABLE TBNF_LOGS
ADD CONSTRAINT PK_TBNF_LOGS
PRIMARY KEY (ID);

COMMENT ON COLUMN TBNF_LOGS.ORIGEM IS
'NFE - NOTA FISCAL DE ENTRADA
NFS - NOTA FISCAL DE SAÍDA';

CREATE SEQUENCE GTBNF_LOGS;


CREATE TRIGGER TBNF_LOGS_B01I FOR TBNF_LOGS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
    NEW.ID = GEN_ID(GTBNF_LOGS,1);
END;

CREATE INDEX TBNF_LOGS_01
ON TBNF_LOGS (NF_ID);

CREATE INDEX TBNF_LOGS_02
ON TBNF_LOGS (ORIGEM);

ALTER TABLE TBNF_LOGS
ADD DATAHORA TIMESTAMP
DEFAULT 'NOW';