--Order 20016225

CREATE TABLE WORKSTATIONBOXPOSITION
(
  WORKSTATION_ID NUMBER NOT NULL,
  BOXNUMBER      NUMBER(3) NOT NULL,
  ROWNUMBER      NUMBER(2) NOT NULL,
  POSITION       NUMBER(2) NOT NULL,
  SYSTEMUSER_ID  NUMBER DEFAULT 0 NOT NULL,
  TIMESTAMP      DATE DEFAULT SYSDATE NOT NULL
);

ALTER TABLE WORKSTATIONBOXPOSITION
  ADD CONSTRAINT XPKWORKSTATIONBOXPOSITION PRIMARY KEY (WORKSTATION_ID, BOXNUMBER);

CREATE INDEX XIF1WORKSTATIONBOXPOSITION ON WORKSTATIONBOXPOSITION (WORKSTATION_ID);

ALTER TABLE WORKSTATIONBOXPOSITION
  ADD CONSTRAINT WORKSTATIONBOXPOSITION_WORKST FOREIGN KEY (WORKSTATION_ID)
  REFERENCES WORKSTATION (WORKSTATION_ID) ON DELETE CASCADE;
 
ALTER TABLE WORKSTATIONBOXPOSITION
  ADD CONSTRAINT BOXNUMBER_VALID2
  CHECK (BOXNUMBER BETWEEN 1 AND 999);
ALTER TABLE WORKSTATIONBOXPOSITION
  ADD CONSTRAINT POSITION_VALID2
  CHECK (POSITION BETWEEN 0 AND 99);
ALTER TABLE WORKSTATIONBOXPOSITION
  ADD CONSTRAINT ROWNUMBER_VALID
  CHECK (ROWNUMBER BETWEEN 0 AND 99);