CREATE TABLE TBPREFIXO_EAN (
    ID INTEGER NOT NULL,
    PREFIXO VARCHAR(20),
	STATUS INTEGER,
    DATAHORA TIMESTAMP DEFAULT 'NOW' NOT NULL);

ALTER TABLE TBPREFIXO_EAN
ADD CONSTRAINT PK_TBPREFIXO_EAN
PRIMARY KEY (ID);


COMMENT ON COLUMN TBPREFIXO_EAN.STATUS IS
'0 - INATIVO;
1 - ATIVO;';

CREATE SEQUENCE GTBPREFIXO_EAN;

SET TERM ^ ;

create trigger ttbprefixo_ean_b01i for tbprefixo_ean
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbprefixo_ean,1);
end
^

SET TERM ; ^

INSERT INTO TBPREFIXO_EAN (PREFIXO, STATUS)
SELECT DISTINCT T.PREFIXO, 1 FROM TBEAN T;