CREATE TABLE TPCTPAGDESPPREV
(
    NRTPCTPAGDESPPREV    NUMBER                 NOT NULL,
    CDDESPPREV           VARCHAR2(3)            NOT NULL,
    CDTPCTPAGAR          VARCHAR2(06)           NOT NULL,
    IDATIVOCTPAGDESP     VARCHAR2(1)            DEFAULT 'S' NOT NULL,    
	NRORG             	 NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	 VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        	 DATE            DEFAULT SYSDATE,
    DTULTATU          	 DATE            DEFAULT SYSDATE,
    NRORGINCLUSAO     	 NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERINCLUSAO    	 VARCHAR2(12)    DEFAULT '1' 					NULL,
    NRORGULTATU       	 NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERULTATU      	 VARCHAR2(12)    DEFAULT '1',
		CONSTRAINT CKC_IDATIVOCTPAGDESP CHECK (IDATIVOCTPAGDESP IN ('S', 'N')),
		CONSTRAINT CKC_IDATIVO_CTPAGDESPPREV CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_TPCTPAGDESPPREV PRIMARY KEY (NRTPCTPAGDESPPREV),
		CONSTRAINT UN_TPCTPAGDESPPREV UNIQUE (CDDESPPREV, CDTPCTPAGAR, IDATIVOCTPAGDESP)
)
/

CREATE INDEX GOP00739_FK ON TPCTPAGDESPPREV (CDDESPPREV ASC)
/

ALTER TABLE TPCTPAGDESPPREV
    ADD CONSTRAINT FKGOP00739DESPPREV FOREIGN KEY  (CDDESPPREV)
       REFERENCES DESPPREV (CDDESPPREV)
/

CREATE INDEX GOP00740_FK ON TPCTPAGDESPPREV (CDTPCTPAGAR ASC)
/

ALTER TABLE TPCTPAGDESPPREV
    ADD CONSTRAINT FKGOP00740TIPOCTPAGAR FOREIGN KEY  (CDTPCTPAGAR)
       REFERENCES TIPOCTPAGAR (CDTPCTPAGAR)
/

CREATE SEQUENCE SEQ_TPCTPAGDESPPREV MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/

CREATE INDEX FKGOPFATURAMENTOROP_100 ON FATURAMENTOROP (DTENTRSAID, CDFILIAL, IDTPLANCROP)
/

CREATE INDEX FKGOPFATURAMENTOROP_101 ON FATURAMENTOROP (DTREFERENC, CDFILIAL, IDTPLANCROP)
/

CREATE INDEX FKGOPDEDUCAOROP_100 ON DEDUCAOROP (DTREFERENC, CDFILIAL, IDTPLANCROP)
/

CREATE INDEX FKGOPFILIALROP_100 ON FILIALROP (DTFILIALROP, CDFILIAL)
/