ALTER TABLE PARAVEND ADD IDUTILINTEPROMO VARCHAR2(1) DEFAULT 'N' NOT NULL
   CONSTRAINT CKC_IDUTILINTEPROMO_PARAVEND CHECK (IDUTILINTEPROMO IN ('S','N'))
/

ALTER TABLE PARAVEND ADD CDURLINTEPROMO VARCHAR2(250) NULL
/

ALTER TABLE COMANDAVEN ADD NRCPFINTEPROMO VARCHAR2(20) NULL
/

ALTER TABLE COMANDAVEN ADD IDPEDINTEPROMO VARCHAR2(37) NULL
/

ALTER TABLE VENDA ADD NRCPFINTEPROMO VARCHAR2(20) NULL
/

ALTER TABLE VENDA ADD IDPEDINTEPROMO VARCHAR2(37) NULL
/ 

CREATE TABLE PROMOCOMANDA (
   CDFILIAL          VARCHAR2(4)   	 NOT NULL,
   NRVENDAREST       VARCHAR2(10)  	 NOT NULL,
   NRCOMANDA         VARCHAR2(10)  	 NOT NULL,
   NRSEQPROMOCOM     VARCHAR2(3)     NOT NULL,
   IDPROMOCOM        VARCHAR2(37)  	 NULL,
   NMPROMOCOM        VARCHAR2(100) 	 NULL,
   DSPROMOCOM        VARCHAR2(256) 	 NULL,
   IDTPPROMOCOM      VARCHAR2(1)   	 DEFAULT 'O' NOT NULL,   
   IDTPDESCPROMO     VARCHAR2(1)   	 NULL,   
   VRDESCPROMO       FLOAT         	 NULL,
   VRVENDAPROMO      FLOAT         	 NULL,
   IDUTPROMOCOM      VARCHAR2(1)   	 DEFAULT 'N' 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_PROMOCOMANDA CHECK (IDATIVO IN ('S','N')),
	  CONSTRAINT CKC_IDUTPROMOCOM_PROMOCOMANDA CHECK (IDUTPROMOCOM IN ('S','N')),
	  CONSTRAINT CKC_IDTPDESCPROMO_PROMOCOMANDA CHECK (IDTPDESCPROMO IN ('V','P')),
	  CONSTRAINT CKC_IDTPPROMOCOM_PROMOCOMANDA CHECK (IDTPPROMOCOM IN ('O','P','W')),	
      CONSTRAINT PK_PROMOCOMANDA PRIMARY KEY (CDFILIAL, NRVENDAREST, NRCOMANDA, NRSEQPROMOCOM)
)
/
ALTER TABLE PROMOCOMANDA
   ADD CONSTRAINT FKVND00841COMANDAVEN FOREIGN KEY (CDFILIAL, NRVENDAREST, NRCOMANDA)
      REFERENCES COMANDAVEN (CDFILIAL, NRVENDAREST, NRCOMANDA)
/
CREATE INDEX VND00841_FK ON PROMOCOMANDA (CDFILIAL ASC, NRVENDAREST ASC, NRCOMANDA ASC)
/

CREATE TABLE PROMOVENDA (
   CDFILIAL          VARCHAR2(4)   	 NOT NULL,
   CDCAIXA           VARCHAR2(3)   	 NOT NULL,
   NRSEQVENDA        VARCHAR2(10)  	 NOT NULL,
   NRSEQPROMOVEN     VARCHAR2(3)   	 NOT NULL,
   IDPROMOVEN        VARCHAR2(37)  	 NULL,
   NMPROMOVEN        VARCHAR2(100) 	 NULL,
   DSPROMOVEN        VARCHAR2(256) 	 NULL,
   IDTPPROMOVEN      VARCHAR2(1)   	 DEFAULT 'O' NOT NULL,  
   IDTPDESCPROMO     VARCHAR2(1)   	 NULL,
   VRDESCPROMO       FLOAT         	 NULL,
   VRVENDAPROMO      FLOAT         	 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_IDTPPROMOVEN_PROMOVENDA CHECK (IDTPPROMOVEN IN ('O','P','W')),
	  CONSTRAINT CKC_IDTPDESCPROMO_PROMOVENDA CHECK (IDTPDESCPROMO IN ('V','P')),
	  CONSTRAINT CKC_IDATIVO_PROMOVENDA CHECK (IDATIVO IN ('S','N')),
      CONSTRAINT PK_PROMOVENDA PRIMARY KEY (CDFILIAL, CDCAIXA, NRSEQVENDA, NRSEQPROMOVEN)
)
/
ALTER TABLE PROMOVENDA
   ADD CONSTRAINT FKVND00842VENDA FOREIGN KEY (CDFILIAL, CDCAIXA, NRSEQVENDA)
      REFERENCES VENDA (CDFILIAL, CDCAIXA, NRSEQVENDA)
/

CREATE INDEX VND00842_FK ON PROMOVENDA (CDFILIAL ASC, CDCAIXA ASC, NRSEQVENDA ASC)
/