CREATE TABLE PAR_PARAMFATURA(
    NRPARAMFATURA   NUMBER  NOT NULL,
    NRPARCNEGOCIO   NUMBER  NOT NULL,
    CDFILIALFATURA  VARCHAR2(4) NULL, 
    CDSERIENF       VARCHAR2(5) NULL,
    CDEMPRESA       VARCHAR2(2) NULL,
    CDINSCESTA      VARCHAR2(16) NULL,
    CDINSCMUNI      VARCHAR2(16) NULL,
    NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_PAR_PARAMFATURA 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'
)
/

ALTER TABLE PAR_PARAMFATURA ADD CONSTRAINT PK_PAR_PARAMFATURA PRIMARY KEY (NRPARAMFATURA)
/

CREATE INDEX SM00320_FK ON PAR_PARAMFATURA (NRPARCNEGOCIO ASC)
/

ALTER TABLE PAR_PARAMFATURA 
  ADD CONSTRAINT FKSM00320PARCNEG_PAR_PARAMFAT FOREIGN KEY (NRPARCNEGOCIO)
      REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/

CREATE INDEX SM00321_FK ON PAR_PARAMFATURA (CDFILIALFATURA ASC)
/

ALTER TABLE PAR_PARAMFATURA
  ADD CONSTRAINT FKSM00321FILIAL_PAR_PARAMFAT FOREIGN KEY (CDFILIALFATURA)
      REFERENCES FILIAL (CDFILIAL)
/

CREATE INDEX SM00322_FK ON PAR_PARAMFATURA (CDSERIENF ASC , CDEMPRESA ASC, CDINSCESTA ASC, CDINSCMUNI ASC)
/

ALTER TABLE PAR_PARAMFATURA
   ADD CONSTRAINT FKSM00322SERIENF_PAR_PARAMFAT FOREIGN KEY (CDSERIENF, CDEMPRESA, CDINSCESTA, CDINSCMUNI)
      REFERENCES SERIENF (CDSERIE, CDEMPRESA, CDINSCESTA, CDINSCMUNI)
/