CREATE TABLE CREDPRESCFOPNCM
(
	CDEMPRESA        VARCHAR2(02)           NOT NULL,
	CDINSCESTA       VARCHAR2(16)           NOT NULL,
	CDCFOPPADRAO     VARCHAR2(10)           NOT NULL,
	CDCLASFISC       VARCHAR2(10)           NOT NULL,
	DSOUTROSCRED     VARCHAR2(250)          NOT NULL,
	VRALIQUOTA       FLOAT                  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_IDATIVO_CREDPRESCFOPNCM CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_CREDPRESCFOPNCM PRIMARY KEY (CDEMPRESA, CDINSCESTA, CDCFOPPADRAO, CDCLASFISC)
)

/

CREATE INDEX FIS00858_FK ON CREDPRESCFOPNCM (CDEMPRESA ASC, CDINSCESTA ASC) 
/

ALTER TABLE CREDPRESCFOPNCM
    ADD CONSTRAINT FKFIS00858INSCREST FOREIGN KEY  (CDEMPRESA, CDINSCESTA)
       REFERENCES INSCRESTAD (CDEMPRESA, CDINSCESTA)
/

CREATE INDEX FIS00859_FK ON CREDPRESCFOPNCM (CDCFOPPADRAO ASC) 
/

ALTER TABLE CREDPRESCFOPNCM
    ADD CONSTRAINT FKFIS00859CFOPPADR FOREIGN KEY  (CDCFOPPADRAO)
       REFERENCES CFOPPADRAO (CDCFOPPADRAO)
/