CREATE TABLE IMPARQXMLNFCE (
   NRIMPARQXMLNFCE NUMBER NOT NULL,
   NRACESSONFCE   VARCHAR2(50) NOT NULL,
   DSNOMEARQUIVO  VARCHAR2(250) NOT NULL,
   DSARQXMLNFCE   CLOB NOT NULL,
   DTENTRVENDA    DATE NOT NULL,
   CDFILIAL       VARCHAR2(4) NOT NULL,
   CDCAIXA        VARCHAR2(3) NOT NULL,
   IDSTATUSIMPARQ VARCHAR2(1) DEFAULT 'N'  NOT NULL,
		CONSTRAINT CKC_IDSTATUSIMPARQ_IMPARQXM CHECK (IDSTATUSIMPARQ IN ('S', 'N')),
   NRSEQVENDA     VARCHAR2(10) NULL,
   NRORG          NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO        VARCHAR2(1)   DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_IMPARQXMLNFCE CHECK (IDATIVO IN ('S','N')),
   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' NULL,
   CONSTRAINT UN_IMPARQXMLNFCE UNIQUE (NRACESSONFCE),
   CONSTRAINT PK_IMPARQXMLNFCE PRIMARY KEY (NRIMPARQXMLNFCE)
)
/

CREATE INDEX IDX_IMPARQXMLNFCE_01 ON IMPARQXMLNFCE (DTENTRVENDA ASC, NRIMPARQXMLNFCE ASC)
/

CREATE INDEX VND00829_FK ON IMPARQXMLNFCE (CDFILIAL ASC, CDCAIXA ASC, NRSEQVENDA ASC)
/

ALTER TABLE IMPARQXMLNFCE
   ADD CONSTRAINT FKVND00829VENDA FOREIGN KEY (CDFILIAL, CDCAIXA, NRSEQVENDA)
      REFERENCES VENDA (CDFILIAL, CDCAIXA, NRSEQVENDA) ON DELETE CASCADE
/

CREATE TABLE MSGIMPARQXMLNFCE (
   NRMSGIMPARQXMLNFCE NUMBER NOT NULL,
   NRIMPARQXMLNFCE NUMBER NOT NULL,
   IDTIPOMSG   VARCHAR2(1)   DEFAULT 'E' NOT NULL
		CONSTRAINT CKC_IDTIPOMSG_MSGIMPARQXMLNFCE CHECK (IDTIPOMSG IN ('E','A')),
   CDFILIAL       VARCHAR2(4)   NULL,
   CDCAIXA        VARCHAR2(3)   NULL,
   NRNOTAFISCALCE VARCHAR2(9)   NULL,
   NRACESSONFCE   VARCHAR2(50)  NULL,
   CDPRODUTO      VARCHAR2(30)  NULL,
   NMPRODUTO      VARCHAR2(50)  NULL,
   DSERRO         VARCHAR2(300) NULL,
   DSAJUDA        VARCHAR2(300) NULL,
   CDTIPORECE     VARCHAR2(3)   NULL,  
   NRORG          NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO        VARCHAR2(1)   DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_MSGIMPARQXMLNFCE CHECK (IDATIVO IN ('S','N')),
   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' NULL,
		CONSTRAINT PK_MSGIMPARQXMLNFCE PRIMARY KEY (NRMSGIMPARQXMLNFCE)
)
/

CREATE INDEX VND00830_FK ON MSGIMPARQXMLNFCE (NRIMPARQXMLNFCE ASC)
/

ALTER TABLE MSGIMPARQXMLNFCE
   ADD CONSTRAINT FKVND00830IMPARQXMLNFCE FOREIGN KEY (NRIMPARQXMLNFCE)
      REFERENCES IMPARQXMLNFCE (NRIMPARQXMLNFCE) ON DELETE CASCADE
/

UPDATE PRODUTOADQ SET NMPRODUTOADQ = 'OUROCARD AGRO DEBITO' WHERE CDPRODUTOADQ = '536'
/

COMMIT
/