CREATE TABLE TBCD_PLACAS_HISTORICO (
    ID INTEGER NOT NULL,
    PRODUTO INTEGER,
    TAMANHO INTEGER,
    QUANTIDADE NUMERIC(15,4),
    TALAO_ID INTEGER,
    SOBRA_ID INTEGER,
    DESCRICAO VARCHAR(100),
    TIPO INTEGER,
    OPERADOR_ID INTEGER,
    DATAHORA     TIMESTAMP DEFAULT 'NOW'
);

ALTER TABLE TBCD_PLACAS_HISTORICO
ADD CONSTRAINT PK_TBCD_PLACAS_HISTORICO
PRIMARY KEY (ID);

CREATE SEQUENCE GTBCD_PLACAS_HISTORICO;

ALTER TABLE TBCD_PLACAS_HISTORICO
    ADD DATA_PRODUCAO TIMESTAMP;
	
ALTER TABLE TBCD_PLACAS_HISTORICO
    ALTER DATA_PRODUCAO TYPE DATE;

CREATE OR ALTER trigger ttbcd_placas_historico_b01i for tbcd_placas_historico
active before insert position 0
as
begin
  if (new.id is null) then
  begin
    new.id = gen_id(gtbcd_placas_historico,1);
  end

  new.data_producao = fn_data_producao();
end;




