CREATE TABLE TBMDF_LOTE (
    ID INTEGER NOT NULL,
    MDF_ID INTEGER NOT NULL,
    LOTE INTEGER,
    RECIBO VARCHAR(20),
    XML CHAR(2),
    PROTOCOLO VARCHAR(20),
    PROTOCOLO_CANCELAMENTO VARCHAR(20),
    OBSERVACAO VARCHAR(255),
    DATAHORA TIMESTAMP DEFAULT 'NOW');
	
ALTER TABLE TBMDF_LOTE
ADD CONSTRAINT PK_TBMDF_LOTE
PRIMARY KEY (ID);

CREATE SEQUENCE GTBMDF_LOTE;

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


CREATE INDEX TBMDF_LOTE_01
ON TBMDF_LOTE (MDF_ID);

CREATE INDEX TBMDF_LOTE_02
ON TBMDF_LOTE (LOTE);

CREATE INDEX TBMDF_LOTE_03
ON TBMDF_LOTE (RECIBO);

CREATE INDEX TBMDF_LOTE_04
ON TBMDF_LOTE (XML);

CREATE INDEX TBMDF_LOTE_05
ON TBMDF_LOTE (PROTOCOLO);

CREATE INDEX TBMDF_LOTE_06
ON TBMDF_LOTE (PROTOCOLO_CANCELAMENTO);