CREATE TABLE CTBLDESPPREV
(
    NRCTBLDESPPREV       NUMBER                 NOT NULL,
    CDDESPPREV           VARCHAR2(3)            NOT NULL,
    CDCONTCTBL           VARCHAR2(20)           NOT NULL,
    IDATIVOCTBLDESP      VARCHAR2(1)            DEFAULT 'S' NOT NULL
        CONSTRAINT CKC_IDATIVOCTBLDESP CHECK (IDATIVOCTBLDESP IN ('S', 'N')),
    NRORG                NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO              VARCHAR2(1)            DEFAULT 'S' NOT NULL
        CONSTRAINT CKC_IDATIVO_CTBLDESPPREV CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO           DATE                   NULL,
    DTULTATU             DATE                   NULL,
    NRORGINCLUSAO        NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
    CDOPERINCLUSAO       VARCHAR2(12)           NULL,
    NRORGULTATU          NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
    CDOPERULTATU         VARCHAR2(12)           NULL,
		CONSTRAINT PK_CTBLDESPPREV PRIMARY KEY (NRCTBLDESPPREV),
		CONSTRAINT UN_CTBLDESPPREV UNIQUE (CDDESPPREV, CDCONTCTBL, IDATIVOCTBLDESP)
)
/

CREATE INDEX GOP00731_FK ON CTBLDESPPREV (CDDESPPREV ASC)
/

ALTER TABLE CTBLDESPPREV
    ADD CONSTRAINT FKGOP00731DESPPREV FOREIGN KEY  (CDDESPPREV)
       REFERENCES DESPPREV (CDDESPPREV)
/

CREATE INDEX GOP00732_FK ON CTBLDESPPREV (CDCONTCTBL ASC)
/

ALTER TABLE CTBLDESPPREV
    ADD CONSTRAINT FKGOP00732CONTCTBL FOREIGN KEY  (CDCONTCTBL)
       REFERENCES CONTCTBL (CDCONTCTBL)
/