CREATE TABLE TBSQL_EXEC (
    ID INTEGER NOT NULL,
    SQL BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    ERRO BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    DATA_EXECUTAR TIMESTAMP,
    DATA_EXECUTADO TIMESTAMP,
    STATUS INTEGER DEFAULT 0);

ALTER TABLE TBSQL_EXEC
ADD CONSTRAINT PK_TBSQL_EXEC
PRIMARY KEY (ID);

COMMENT ON COLUMN TBSQL_EXEC.STATUS IS
'0 - pendente
1 - executado';

CREATE SEQUENCE GTBSQL_EXEC;

create trigger ttbsql_exec_b01i for tbsql_exec
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbsql_exec,1);
end;

CREATE INDEX ITBSQL_EXEC_02
ON TBSQL_EXEC (DATA_EXECUTAR,STATUS);

CREATE INDEX ITBSQL_EXEC_01
ON TBSQL_EXEC (STATUS);

