-- ABS-150532
CREATE SEQUENCE SEQ_PLANTDEPARTMENTMACHINE
START WITH 1
INCREMENT BY 1;

CREATE TABLE PLANTDEPARTMENTMACHINE (
  PLANTDEPARTMENTMACHINE_ID NUMBER NOT NULL,
  PLANTDEPARTMENT_ID NUMBER NOT NULL,
  MACHINE_ID NUMBER NOT NULL,
  SYSTEMUSER_ID NUMBER NOT NULL,
  TIMESTAMP DATE NOT NULL
);
  
ALTER TABLE PLANTDEPARTMENTMACHINE 
ADD CONSTRAINT XPKPLANTDEPARTMENTMACHINE PRIMARY KEY (PLANTDEPARTMENTMACHINE_ID);

CREATE UNIQUE INDEX XAK1PLANTDEPARTMENTMACHINE ON PLANTDEPARTMENTMACHINE(MACHINE_ID);
CREATE INDEX XIF1PLANTDEPARTMENTMACHINE ON PLANTDEPARTMENTMACHINE (PLANTDEPARTMENT_ID);

ALTER TABLE PLANTDEPARTMENTMACHINE
ADD CONSTRAINT FK_PLANTDEPARTMENTMACHINE_PLANTDPTID FOREIGN KEY (PLANTDEPARTMENT_ID) REFERENCES PLANTDEPARTMENT (PLANTDEPARTMENT_ID) ON DELETE CASCADE;

ALTER TABLE PLANTDEPARTMENTMACHINE
ADD CONSTRAINT FK_PLANTDEPARTMENTMACHINE_MACHINEID FOREIGN KEY (MACHINE_ID) REFERENCES MACHINE (MACHINE_ID) ON DELETE CASCADE;