CREATE TABLE TBNFS_ITEM_TALAO_SALDO (
    ID INTEGER NOT NULL,
    NFS_ID INTEGER,
    NFS_ITEM_ID INTEGER,
    TALAO_ID INTEGER,
    QUANTIDADE NUMERIC(15,4),
    DATAHORA TIMESTAMP DEFAULT 'NOW' NOT NULL);

ALTER TABLE TBNFS_ITEM_TALAO_SALDO
ADD CONSTRAINT PK_TBNFS_ITEM_TALAO_SALDO
PRIMARY KEY (ID);

CREATE SEQUENCE GTBNFS_ITEM_TALAO_SALDO;

SET TERM ^ ;

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

SET TERM ; ^

CREATE INDEX ITBNFS_ITEM_TALAO_SALDO_01
ON TBNFS_ITEM_TALAO_SALDO (NFS_ID);

CREATE INDEX ITBNFS_ITEM_TALAO_SALDO_02
ON TBNFS_ITEM_TALAO_SALDO (NFS_ITEM_ID);

CREATE INDEX ITBNFS_ITEM_TALAO_SALDO_03
ON TBNFS_ITEM_TALAO_SALDO (TALAO_ID);

