CREATE TABLE DIASCONSUMO( 
 NRDIASCONSUMO  	 INTEGER  			NOT NULL,
 CDPERIENTR       	 VARCHAR2(2) 		NOT NULL,  
 DIENTREGA       	 VARCHAR2(2) 		NOT NULL, 
 DIACONSUMOINI       VARCHAR2(2) 		NOT NULL,
 DIACONSUMOFIN       VARCHAR2(2) 		NOT NULL,
 NRORG               NUMBER  			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO           VARCHAR2(1)      	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_DIASCONSUMO  CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO        DATE                   NULL,
   DTULTATU          DATE                   NULL,
   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 PK_NRDIASCONSUMO PRIMARY KEY (NRDIASCONSUMO),
		CONSTRAINT UN_NRDIASCONSUMO UNIQUE (CDPERIENTR, DIENTREGA, DIACONSUMOINI, DIACONSUMOFIN)
) 
/
CREATE SEQUENCE SEQ_NRDIASCONSUMO INCREMENT BY 1 MINVALUE 1
/
CREATE INDEX SUP00331_FK ON DIASCONSUMO (CDPERIENTR ASC,DIENTREGA ASC)
/
ALTER TABLE DIASCONSUMO ADD
	CONSTRAINT  FKSUP00331DIASENTR_DCONS  FOREIGN KEY (CDPERIENTR, DIENTREGA) 
		REFERENCES DIASENTR (CDPERIENTR, DIENTREGA) ON DELETE CASCADE
/