--ABS-62480/ ABS-64157

DROP SEQUENCE SEQ_CONTRACTPRIMARYTOSECLINK;

DROP TABLE CONTRACTPRIMARYTOSECLINK;

-- CONTRACTPRIMARYTOSECLINK TABLE --
CREATE TABLE CONTRACTPRIMARYTOSECLINK
(
  SECONDARYCONTRACT_ID NUMBER NOT NULL,
  PRIMARYCONTRACT_ID   NUMBER NOT NULL,
  TIMESTAMP            DATE NOT NULL,
  SYSTEMUSER_ID        NUMBER NOT NULL
)
;

ALTER TABLE CONTRACTPRIMARYTOSECLINK
  ADD CONSTRAINT XPKCONTRACTPRIMARYTOSECLINK PRIMARY KEY (SECONDARYCONTRACT_ID);
  
CREATE INDEX XIF1CONTRACTPRIMARYTOSECLINK ON CONTRACTPRIMARYTOSECLINK (PRIMARYCONTRACT_ID);

ALTER TABLE CONTRACTPRIMARYTOSECLINK
  ADD CONSTRAINT CONTRACTPRIMARYTOSECLINK_C1 FOREIGN KEY (SECONDARYCONTRACT_ID)
  REFERENCES CONTRACT (CONTRACT_ID) ON DELETE CASCADE;
  
ALTER TABLE CONTRACTPRIMARYTOSECLINK
  ADD CONSTRAINT CONTRACTPRIMARYTOSECLINK_C2 FOREIGN KEY (PRIMARYCONTRACT_ID)
  REFERENCES CONTRACT (CONTRACT_ID);



