CREATE TABLE FILIALCADA (
  NRFILIALCADA NUMBER(10) NOT NULL, 
  NRCONFIGALCADA NUMBER(10) NOT NULL, 
  CDFILIAL VARCHAR2(4) NOT NULL, 
  NRORG NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 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_ALCADAFILI PRIMARY KEY(NRFILIALCADA)
)
/
ALTER TABLE FILIALCADA ADD CONSTRAINT CKC_IDATIVO_FILIALCADA CHECK (IDATIVO IN ('S','N'))
/
ALTER TABLE FILIALCADA ADD CONSTRAINT FKCMP00570CONFIGALCADA FOREIGN KEY (NRCONFIGALCADA) REFERENCES CONFIGALCADA (NRCONFIGALCADA)
/
CREATE INDEX FKCMP00570CONFIGALCADA ON FILIALCADA (NRCONFIGALCADA)
/
ALTER TABLE FILIALCADA ADD CONSTRAINT FKCMP00571FILIAL FOREIGN KEY (CDFILIAL) REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKCMP00571FILIAL ON FILIALCADA (CDFILIAL)