-- ABS-62313/ ABS-64862

-- CONTRACTSALESLEADS TABLE --
CREATE TABLE CONTRACTSALESLEADS
(
  CONTRACT_ID   NUMBER NOT NULL,
  EMPLOYEE_ID   NUMBER NOT NULL,
  SYSTEMUSER_ID NUMBER NOT NULL,
  TIMESTAMP     DATE NOT NULL
);

ALTER TABLE CONTRACTSALESLEADS
  ADD CONSTRAINT XPKCONTRACTSALESLEADS PRIMARY KEY (CONTRACT_ID, EMPLOYEE_ID);
  
CREATE INDEX XIF1CONTRACTSALESLEADS ON CONTRACTSALESLEADS (CONTRACT_ID ASC);
CREATE INDEX XIF2CONTRACTSALESLEADS ON CONTRACTSALESLEADS (EMPLOYEE_ID ASC);

ALTER TABLE CONTRACTSALESLEADS
  ADD CONSTRAINT CONTRACTSALESLEADS_CON FOREIGN KEY (CONTRACT_ID)
  REFERENCES CONTRACT (CONTRACT_ID) ON DELETE CASCADE;
  
ALTER TABLE CONTRACTSALESLEADS
  ADD CONSTRAINT CONTRACTSALESLEADS_EMPL FOREIGN KEY (EMPLOYEE_ID)
  REFERENCES EMPLOYEE (EMPLOYEE_ID);
