CREATE TABLE KDS_TEMP_SETOREST (
   CDFILIAL        VARCHAR2(4)  NOT NULL,
   CDSETOR         VARCHAR2(4)  NOT NULL,
   NRPEDIDOFOS     VARCHAR2(10) NOT NULL,
   NRTEMPOTOTAL    NUMBER       NOT NULL,
   DTHRFIMPRODUCAO DATE         NOT NULL,
   NRORG           NUMBER       DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO         VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_KDS_TEMP_SETOREST CHECK (IDATIVO IN ('S','N')),
   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' NULL,
		CONSTRAINT PK_KDS_TEMP_SETOREST PRIMARY KEY (CDFILIAL, CDSETOR, NRPEDIDOFOS)
)
/

CREATE INDEX VND00837_FK ON KDS_TEMP_SETOREST (CDFILIAL ASC, CDSETOR ASC)
/

ALTER TABLE KDS_TEMP_SETOREST
   ADD CONSTRAINT FKVND00837SETORFILIAL FOREIGN KEY (CDFILIAL, CDSETOR)
      REFERENCES SETORFILIAL (CDFILIAL, CDSETOR)
/

CREATE INDEX VND00838_FK ON KDS_TEMP_SETOREST (CDFILIAL ASC, NRPEDIDOFOS ASC)
/

ALTER TABLE KDS_TEMP_SETOREST
   ADD CONSTRAINT FKVND00838PEDIDOFOS FOREIGN KEY (CDFILIAL, NRPEDIDOFOS)
      REFERENCES PEDIDOFOS (CDFILIAL, NRPEDIDOFOS)
/