CREATE TABLE CONFTELAINICARD(
    CDCONFTELA 		  VARCHAR2(5) 	  NOT NULL,
    NMCONFTELA 		  VARCHAR2(50) 	  NOT NULL,
    DSCONFTELA 		  VARCHAR2(200)   NULL,
    CDFILIAL 		  VARCHAR2(4) 	  NOT NULL,
    CDLOJA 			  VARCHAR2(10) 	  NOT NULL,
    ORDEMEXIBE 	  	  NUMBER 	      NULL,
    DTINIVIGENCIA 	  DATE 			  NOT NULL,
    DTFIMVIGENCIA 	  DATE 			  NOT NULL,
    MIDIACARDAPIO 	  VARCHAR2(1000)  NULL,
	TPMIDIA 		  VARCHAR2(6) 	  NULL,
	NMARQUIVO 		  VARCHAR2(100)   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_CONFTELAINICARD CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_CONFTELAINICARD PRIMARY KEY (CDCONFTELA,CDFILIAL,CDLOJA,NRORG)
)
/

ALTER TABLE CONFTELAINICARD 
    ADD CONSTRAINT  FKVND00864CDFILIALCARD FOREIGN KEY(CDFILIAL) 
        REFERENCES FILIAL(CDFILIAL) 
/

CREATE INDEX VND00864_FK ON CONFTELAINICARD (CDFILIAL ASC)
/
 
ALTER TABLE CONFTELAINICARD 
    ADD CONSTRAINT FKVND00865CDFILIALCARD FOREIGN KEY(CDFILIAL,CDLOJA) 
        REFERENCES LOJA(CDFILIAL,CDLOJA) 
/

CREATE INDEX VND00865_FK ON CONFTELAINICARD (CDFILIAL ASC,CDLOJA ASC)
/