ALTER TABLE VIATURA ADD IDREBOQUE VARCHAR2(01) DEFAULT 'N' NOT NULL
   CONSTRAINT CKC_VIATURA_IDREBOQUE CHECK (IDREBOQUE IN ('N', 'S'))
/
CREATE TABLE REBOQUEMDFE(
   CDVIATURA      	 VARCHAR2(04)												NOT NULL,
   NRORG 		 	 NUMBER	   	   DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
   IDATIVO           VARCHAR2(1)   DEFAULT 'S' 									NOT NULL,
      CONSTRAINT CKC_IDATIVO_REBOQUEMDFE CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO        DATE                   									NULL,
   DTULTATU          DATE                 										NULL,
   NRORGINCLUSAO     NUMBER        DEFAULT 1 									NULL,
   CDOPERINCLUSAO    VARCHAR2(12)  DEFAULT '1' 									NULL,
   NRORGULTATU       NUMBER        DEFAULT 1 									NULL,
   CDOPERULTATU 	 VARCHAR2(12)  DEFAULT '1' 									NULL,
   NRLANCTOMDFE   	 VARCHAR2(10) 												NOT NULL,
   CDREBOQUE      	 VARCHAR2(04) 												NOT NULL,
      CONSTRAINT PK_REBOQUEMDFE PRIMARY KEY (CDVIATURA, NRLANCTOMDFE, CDREBOQUE)
)
/
ALTER TABLE REBOQUEMDFE
   ADD CONSTRAINT FKFIS00729MDFE FOREIGN KEY (CDVIATURA, NRLANCTOMDFE)
      REFERENCES MDFE (CDVIATURA, NRLANCTOMDFE) ON DELETE CASCADE
/
ALTER TABLE REBOQUEMDFE
   ADD CONSTRAINT FKFIS00730REBOQUEMDFE FOREIGN KEY (CDREBOQUE)
      REFERENCES VIATURA (CDVIATURA)