CREATE TABLE CUPOMDESCFOS( 
   CDCUPOMDESCFOS 	VARCHAR2(10) 	NOT NULL,
   DSCUPOMDESCFOS 	VARCHAR2(100) 	NOT NULL,
   IDTIPODESC 		VARCHAR2(1) 	DEFAULT 'V' NOT NULL,
   VRDESCCUPOM 		NUMBER 			NOT NULL,
   DTINIVIGENCIA 	DATE 			NOT NULL,
   DTFIMVIGENCIA 	DATE 			NOT NULL,
   IDUSOUNICO 		VARCHAR2(1) 	DEFAULT 'N' NOT NULL,
   NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_CUPOMDESCFOS CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 		DATE 			NULL,
   DTULTATU 		DATE 			NULL,
   NRORGINCLUSAO 	NUMBER 			NULL,
   CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1' NULL,
   NRORGULTATU 		NUMBER 			NULL,
   CDOPERULTATU 	VARCHAR2(12) 	DEFAULT '1'
)
/
ALTER TABLE CUPOMDESCFOS ADD CONSTRAINT PK_CUPOMDESCFOS PRIMARY KEY (CDCUPOMDESCFOS)
/
ALTER TABLE CUPOMDESCFOS ADD CONSTRAINT CKC_CUPOMDESCFOS_IDUSOUNICO CHECK (IDUSOUNICO IN ('N', 'S'))
/
ALTER TABLE CUPOMDESCFOS ADD CONSTRAINT CKC_CUPOMDESCFOS_IDTIPODESC CHECK (IDTIPODESC IN ('V', 'P'))
/
CREATE TABLE PRODCUPOMDESC(
   CDCUPOMDESCFOS 	VARCHAR2(10) 	NOT NULL,
   CDPRODUTO 		VARCHAR2(10) 	NOT NULL,
   NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_PRODCUPOMDESC CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO		DATE 			NULL,
   DTULTATU 		DATE 			NULL,
   NRORGINCLUSAO 	NUMBER 			NULL,
   CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1' NULL,
   NRORGULTATU 		NUMBER 			NULL,
   CDOPERULTATU 	VARCHAR2(12) 	DEFAULT '1'
)
/
ALTER TABLE PRODCUPOMDESC ADD CONSTRAINT PK_PRODCUPOMDESC PRIMARY KEY (CDCUPOMDESCFOS, CDPRODUTO)
/
CREATE INDEX VND00775_FK ON PRODCUPOMDESC (CDPRODUTO ASC)
/
ALTER TABLE PRODCUPOMDESC ADD 
	CONSTRAINT FKVND00775PRODUTO FOREIGN KEY (CDPRODUTO)
		REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX VND00776_FK ON PRODCUPOMDESC (CDCUPOMDESCFOS ASC)
/
ALTER TABLE PRODCUPOMDESC ADD 	
	CONSTRAINT FKVND00776CUPOMDESCFOS FOREIGN KEY (CDCUPOMDESCFOS)
		REFERENCES CUPOMDESCFOS (CDCUPOMDESCFOS)
/
CREATE TABLE FILIALCUPOMDESC (
   CDCUPOMDESCFOS 	VARCHAR2(10) 	NOT NULL,
   CDFILIAL 		VARCHAR2(04) 	NOT NULL,
   NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_FILIALCUPOMDESC CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 		DATE 			NULL,
   DTULTATU 		DATE 			NULL,
   NRORGINCLUSAO 	NUMBER 			NULL,
   CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1' NULL,
   NRORGULTATU 		NUMBER 			NULL,
   CDOPERULTATU 	VARCHAR2(12) 	DEFAULT '1'
)
/
ALTER TABLE FILIALCUPOMDESC ADD CONSTRAINT PK_FILIALCUPOMDESC PRIMARY KEY (CDCUPOMDESCFOS, CDFILIAL)
/
CREATE INDEX VND00777_FK ON FILIALCUPOMDESC (CDFILIAL ASC)
/
ALTER TABLE FILIALCUPOMDESC ADD 
	CONSTRAINT FKVND00777FILIAL FOREIGN KEY (CDFILIAL)
		REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX VND00778_FK ON FILIALCUPOMDESC (CDCUPOMDESCFOS ASC)
/
ALTER TABLE FILIALCUPOMDESC ADD 
	CONSTRAINT FKVND00778CUPOMDESCFOS FOREIGN KEY (CDCUPOMDESCFOS)
		REFERENCES CUPOMDESCFOS (CDCUPOMDESCFOS)
/
ALTER TABLE PARAMGERAL ADD IDUTCUPOMDESC VARCHAR2(01) DEFAULT 'N' NOT NULL
/
ALTER TABLE PARAMGERAL ADD CONSTRAINT CKC_PARAMGERAL_IDUTCUPOMDESC CHECK (IDUTCUPOMDESC IN ('N', 'S'))
/
CREATE TABLE USOCUPOMDESCFOS(
   CDCUPOMDESCFOS 	VARCHAR2(10) 	NOT NULL,
   CDFILIAL 		VARCHAR2(04) 	NOT NULL,
   CDCAIXA 			VARCHAR2(03) 	NOT NULL,
   NRSEQVENDA 		VARCHAR2(10) 	NOT NULL,
   NRSEQUITVEND 	VARCHAR2(03) 	NOT NULL,
   NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_USOCUPDESCFOS CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 		DATE 			NULL,
   DTULTATU 		DATE 			NULL,
   NRORGINCLUSAO 	NUMBER 			NULL,
   CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1' NULL,
   NRORGULTATU 		NUMBER 			NULL,
   CDOPERULTATU 	VARCHAR2(12) 	DEFAULT '1'
)
/
ALTER TABLE USOCUPOMDESCFOS ADD CONSTRAINT PK_USOCUPOMDESCFOS PRIMARY KEY (CDCUPOMDESCFOS, CDFILIAL, CDCAIXA, NRSEQVENDA, NRSEQUITVEND)
/
CREATE INDEX VND00779_FK ON USOCUPOMDESCFOS (CDCUPOMDESCFOS ASC)
/
ALTER TABLE USOCUPOMDESCFOS ADD 
	CONSTRAINT FKVND00779CUPOMDESCFOS FOREIGN KEY (CDCUPOMDESCFOS)
		REFERENCES CUPOMDESCFOS (CDCUPOMDESCFOS)
/
CREATE INDEX VND00780_FK ON USOCUPOMDESCFOS (CDFILIAL ASC)
/
ALTER TABLE USOCUPOMDESCFOS ADD 
	CONSTRAINT FKVND00780FILIAL FOREIGN KEY (CDFILIAL)
		REFERENCES FILIAL (CDFILIAL)
/
ALTER TABLE ITCOMANDAVEN ADD CDCUPOMDESCFOS VARCHAR2(10)