CREATE TABLE RATEIOPADRAOFIS
   (	
    CDRATEIOPADRAO 		VARCHAR2(4 ) 			NOT NULL , 
	DSRATEIOPADRAO 		VARCHAR2(100 ), 
	IDRATEIOPADRAO 		VARCHAR2(3 ), 
	NRORG 				NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL , 
	IDATIVO 			VARCHAR2(1 ) 			DEFAULT 'S' NOT NULL , 
	DTINCLUSAO 			DATE 					NULL, 
	DTULTATU 			DATE 					NULL, 
	NRORGINCLUSAO 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERINCLUSAO 		VARCHAR2(12 ) 			DEFAULT '1', 
	NRORGULTATU 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERULTATU 		VARCHAR2(12 )			DEFAULT '1', 
		CONSTRAINT CKC_IDRATEIOPADRAO_RATEIOPADRA CHECK ( IDRATEIOPADRAO IN ( 'ENT', 'SAI', 'SME' ) ) , 
		PRIMARY KEY PK_RATEIOPADRAOFIS (CDRATEIOPADRAO)
  )
/
CREATE TABLE RATFISTPOPERAC(	
	IDENTRSAIDOP 		VARCHAR2(1 ) 			NOT NULL , 
	CDTIPOOPER 			VARCHAR2(2 ) 			NOT NULL , 
	CDRATEIOPADRAO 		VARCHAR2(4 ) 			NOT NULL , 
	NRORG 				NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL , 
	IDATIVO 			VARCHAR2(1 ) 			DEFAULT 'S' NOT NULL , 
	DTINCLUSAO 			DATE 					NULL, 
	DTULTATU 			DATE 					NULL, 
	NRORGINCLUSAO 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERINCLUSAO 		VARCHAR2(12 ) 			DEFAULT '1', 
	NRORGULTATU 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERULTATU 		VARCHAR2(12 )			DEFAULT '1',  
	CONSTRAINT PK_RATFISTPOPERAC PRIMARY KEY (IDENTRSAIDOP, CDTIPOOPER, CDRATEIOPADRAO),
  	 CONSTRAINT FKFIS00776TIPOOPERAC FOREIGN KEY (IDENTRSAIDOP, CDTIPOOPER)
	  REFERENCES TIPOOPERAC (IDENTRSAIDOP, CDTIPOOPER) ON DELETE CASCADE , 
	 CONSTRAINT FKFIS00777RATEIOPADRAOFIS FOREIGN KEY (CDRATEIOPADRAO)
	  REFERENCES RATEIOPADRAOFIS (CDRATEIOPADRAO) ON DELETE CASCADE 
)
/
  CREATE INDEX FIS00776_FK ON RATFISTPOPERAC (IDENTRSAIDOP ASC, CDTIPOOPER ASC)
/  
  CREATE INDEX FIS00777_FK ON RATFISTPOPERAC (CDRATEIOPADRAO ASC)
/
CREATE TABLE RATFISCFOPPADRAO(	
    CDCFOPPADRAO 		VARCHAR2(10 ) 			NOT NULL , 
	CDRATEIOPADRAO 		VARCHAR2(4 ) 			NOT NULL , 
	IDENTRSAIDOP 		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 					NULL, 
	DTULTATU 			DATE 					NULL, 
	NRORGINCLUSAO 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERINCLUSAO 		VARCHAR2(12 ) 			DEFAULT '1', 
	NRORGULTATU 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERULTATU 		VARCHAR2(12 )			DEFAULT '1',  
		CONSTRAINT CKC_IDENTRSAIDOP_RATFISCFOPPAD CHECK ( IDENTRSAIDOP IN ( 'E', 'S' )) , 
		CONSTRAINT CKC_IDATIVO_RATFISCFOPPADRAO CHECK (IDATIVO IN ('S','N')) , 
		CONSTRAINT PK_RATFISCFOPPADRAO  PRIMARY KEY (CDCFOPPADRAO, CDRATEIOPADRAO),
		CONSTRAINT FKFIS00778CFOPPADRAO FOREIGN KEY (CDCFOPPADRAO)
			REFERENCES CFOPPADRAO (CDCFOPPADRAO) , 
		CONSTRAINT FKFIS00779RATEIOPADRAOFIS FOREIGN KEY (CDRATEIOPADRAO)
			REFERENCES RATEIOPADRAOFIS (CDRATEIOPADRAO) ON DELETE CASCADE 
)
/   
  CREATE INDEX FIS00778_FK ON RATFISCFOPPADRAO (CDCFOPPADRAO ASC) 
/
  CREATE INDEX FIS00779_FK ON RATFISCFOPPADRAO (CDRATEIOPADRAO ASC) 
/
CREATE TABLE RATFISPRODUTO(	
    CDPRODUTO 			VARCHAR2(10 ) 			NOT NULL , 
	CDRATEIOPADRAO 		VARCHAR2(4 ) 			NOT NULL , 
	IDENTRSAIDOP 		VARCHAR2(1 ) 			NOT NULL , 
	NRORG 				NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL , 
	IDATIVO 			VARCHAR2(1 ) 			DEFAULT 'S' NOT NULL , 
	DTINCLUSAO 			DATE 					NULL, 
	DTULTATU 			DATE 					NULL, 
	NRORGINCLUSAO 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERINCLUSAO 		VARCHAR2(12 ) 			DEFAULT '1', 
	NRORGULTATU 		NUMBER 					DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
	CDOPERULTATU 		VARCHAR2(12 )			DEFAULT '1',  
	 CONSTRAINT CKC_IDENTRSAIDOP_RATFISPRODUTO CHECK ( IDENTRSAIDOP IN ( 'E', 'S' ) ) , 
	 CONSTRAINT PK_RATFISPRODUTO  PRIMARY KEY (CDPRODUTO, CDRATEIOPADRAO, IDENTRSAIDOP),
  	 CONSTRAINT FKFIS00780PRODUTO FOREIGN KEY (CDPRODUTO)
		REFERENCES PRODUTO (CDPRODUTO) ON DELETE CASCADE , 
	 CONSTRAINT FKFIS00781PRODUTO FOREIGN KEY (CDRATEIOPADRAO)
		REFERENCES RATEIOPADRAOFIS (CDRATEIOPADRAO) ON DELETE CASCADE 
)
/
CREATE INDEX FIS00780_FK ON RATFISPRODUTO (CDPRODUTO ASC) 
/
CREATE INDEX FIS00781_FK ON RATFISPRODUTO (CDRATEIOPADRAO ASC) 
/