--SCRIPT PARA SQLSERVER
CREATE TABLE paletq (
   PALETQ_SEQ     bigint IDENTITY(1,1) NOT NULL,
   PALETQ_PREFIXO varchar(3)           NOT NULL,
   PALETQ_DATA    varchar(8)               NULL,
   PALETQ_HORA    varchar(6)               NULL,
   ETQTIP_CODIGO  varchar(10)              NULL,
PRIMARY KEY (PALETQ_SEQ) );

--SCRIPT PARA ORACLE
CREATE TABLE paletq (
  PALETQ_SEQ       NUMBER(20,0) NOT NULL,
  PALETQ_PREFIXO   VARCHAR2(3)  NOT NULL,
  PALETQ_DATA      VARCHAR2(8)  NULL,
  PALETQ_HORA      VARCHAR2(6)  NULL,
  ETQTIP_CODIGO    VARCHAR2(20) NULL
)
  TABLESPACE users
/

ALTER TABLE paletq
  ADD PRIMARY KEY (
    PALETQ_SEQ
  )
  USING INDEX
    TABLESPACE users
/

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

CREATE OR REPLACE TRIGGER tg_bi_paletq
BEFORE INSERT
    ON paletq
    FOR EACH ROW

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