CREATE TABLE RELACVENDANF (
  CDFILIAL   		VARCHAR2(4) 	NOT NULL,
  CDCAIXA    		VARCHAR2(3) 	NOT NULL,
  NRSEQVENDA 		VARCHAR2(10) 	NOT NULL,
  CDFILIALNF 		VARCHAR2(4) 	NOT NULL,
  NRLANCTONF 		VARCHAR2(10) 	NOT NULL, 
  IDESTORNONFCE 	VARCHAR2(1) 	DEFAULT 'N' NOT NULL 
   CONSTRAINT CKC_IDESTORNONFCE_RELVENNF CHECK (IDESTORNONFCE IN ('S','N')),
  NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_RELACVENDANF 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_RELACVENDANF PRIMARY KEY (CDFILIAL,CDCAIXA,NRSEQVENDA,CDFILIALNF,NRLANCTONF)
)
/
CREATE INDEX VND00773_FK ON RELACVENDANF (CDFILIAL ASC, CDFILIAL ASC, NRSEQVENDA ASC)
/
ALTER TABLE RELACVENDANF ADD
	CONSTRAINT FKVND00773VENDA FOREIGN KEY (CDFILIAL, CDCAIXA, NRSEQVENDA) 
		REFERENCES VENDA (CDFILIAL, CDCAIXA, NRSEQVENDA)
/
CREATE INDEX VND00774_FK ON RELACVENDANF (CDFILIALNF ASC, NRLANCTONF ASC)
/
ALTER TABLE RELACVENDANF ADD
	CONSTRAINT FKVND00774NOTAFISCAL FOREIGN KEY (CDFILIALNF, NRLANCTONF) 
		REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF)
/
ALTER TABLE TIPOOPERAC ADD IDESTORNONFCE VARCHAR2(1) DEFAULT 'N' NOT NULL 
   CONSTRAINT CKC_IDESTORNONFCE_TIPOOPERAC CHECK (IDESTORNONFCE IN ('S','N'))