CREATE TABLE TBMANIFESTO_LOTE (
    ID INTEGER NOT NULL,
    MANIFESTO_ID INTEGER,
    LOTE VARCHAR(20),
    SEQUENCIAL INTEGER,
    PROTOCOLO VARCHAR(20),
    TIPO_EVENTO INTEGER,
	JUSTIFICATIVA VARCHAR(100),
    DATAHORA TIMESTAMP DEFAULT 'NOW');
	
	
	
ALTER TABLE TBMANIFESTO_LOTE
ADD CONSTRAINT PK_TBMANIFESTO_LOTE
PRIMARY KEY (ID);


CREATE SEQUENCE GTBMANIFESTO_LOTE;

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

CREATE INDEX TBMANIFESTO_LOTE_01
ON TBMANIFESTO_LOTE (MANIFESTO_ID);

CREATE INDEX TBMANIFESTO_LOTE_02
ON TBMANIFESTO_LOTE (LOTE);

CREATE INDEX TBMANIFESTO_LOTE_03
ON TBMANIFESTO_LOTE (SEQUENCIAL);