CREATE TABLE alertalog( 
    EMPRES_CODIGO	varchar(4) NOT NULL,
    FILIAL_CODIGO	varchar(4) NOT NULL,
    ALERTALOG_SEQ   BIGINT IDENTITY(1,1) NOT NULL,
    ALERTACFG_SEQ   BIGINT NOT NULL,
    ALERTALOG_DATA  VARCHAR(8),
    ALERTALOG_HORA  VARCHAR(6),
    ALERTALOG_STATUS DECIMAL(2,0),
    ALERTALOG_MSG   TEXT,
    ALERTALOG_DATAFIM VARCHAR(8),
    ALERTALOG_HORAFIM VARCHAR(6),
    PRIMARY KEY(EMPRES_CODIGO,FILIAL_CODIGO,ALERTALOG_SEQ)
);

--script para oracle
CREATE TABLE alertalog (
    EMPRES_CODIGO	varchar(4) NOT NULL,
    FILIAL_CODIGO	varchar(4) NOT NULL,
    ALERTALOG_SEQ   NUMBER(20,0) NOT NULL,
    ALERTACFG_SEQ   NUMBER(20,0) NOT NULL,
    ALERTALOG_DATA  VARCHAR(8),
    ALERTALOG_HORA  VARCHAR(6),
    ALERTALOG_STATUS DECIMAL(2,0),
    ALERTALOG_MSG   VARCHAR2(2000),
    ALERTALOG_DATAFIM VARCHAR(8),
    ALERTALOG_HORAFIM VARCHAR(6)
)
  TABLESPACE users
/

ALTER TABLE alertalog
  ADD PRIMARY KEY (
    ALERTALOG_SEQ
  )
  USING INDEX
    TABLESPACE users
/

CREATE SEQUENCE seq_alertalog
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  INCREMENT BY 1
  NOCYCLE
  NOORDER
  CACHE 20
/


CREATE OR REPLACE TRIGGER tg_bi_alertalog
BEFORE INSERT
    ON alertalog
    FOR EACH ROW

DECLARE
BEGIN
   SELECT seq_alertalog.NEXTVAL
   INTO :NEW.ALERTALOG_SEQ FROM dual;
EXCEPTION
    WHEN OTHERS THEN ROLLBACK;
END;
/