CREATE TABLE DADOSERVPRES (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  NRLANCTONF VARCHAR2(10) NOT NULL, 
  IDNATUOPER VARCHAR2(2) NOT NULL, 
  CDPAISPRESSERV VARCHAR2(4) NOT NULL, 
  SGESTADOPRESSERV VARCHAR2(2) NOT NULL, 
  CDMUNICIPRESSERV VARCHAR2(4) NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL,
  CONSTRAINT PK_DADOSERVPRES PRIMARY KEY(NRORG, CDFILIAL, NRLANCTONF)
)
/
ALTER TABLE DADOSERVPRES ADD CONSTRAINT FKFIS00639DADOSERVPRES FOREIGN KEY (CDFILIAL, NRLANCTONF, NRORG) REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF, NRORG)
/
ALTER TABLE DADOSERVPRES ADD CONSTRAINT FKFIS00640DADOSERVPRES FOREIGN KEY (CDPAISPRESSERV, SGESTADOPRESSERV, CDMUNICIPRESSERV, NRORG) REFERENCES MUNICIPIO (CDPAIS, SGESTADO, CDMUNICIPIO, NRORG)
/
ALTER TABLE DADOSERVPRES ADD CONSTRAINT CKC_IDNATUOPER CHECK (IDNATUOPER IN ('01', '02', '03', '04', '05', '06', '07', '08'))
/
ALTER TABLE DADOSERVPRES ADD CONSTRAINT CKC_IDATIVO_DADOSERVPRES CHECK (IDATIVO IN ('S','N'))
/
CREATE TABLE RELNFSUBSTITUIDO (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  NRLANCTONF VARCHAR2(10) NOT NULL, 
  CDFILIALSUBST VARCHAR2(4) NOT NULL, 
  NRLANCTONFSUBST VARCHAR2(10) NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL,
  CONSTRAINT PK_RELNFSUBSTITUIDO PRIMARY KEY(NRORG, CDFILIAL, NRLANCTONF)
)
/
ALTER TABLE RELNFSUBSTITUIDO ADD CONSTRAINT FKFIS00641RELNFSUBSTITUIDO FOREIGN KEY (CDFILIALSUBST, NRLANCTONFSUBST, NRORG) REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF, NRORG)