--ABS-79070 / ABS-79616
----------------CONTRACTPRODUCTQMGLIMIT ----------------

CREATE SEQUENCE SEQ_CONTRACTPRODUCTQMGLIMIT START WITH 1 INCREMENT BY 1;

CREATE TABLE CONTRACTPRODUCTQMGLIMIT (
           CONTRACTPRODUCTQMGLIMIT_ID NUMBER NOT NULL,
	   CONTRACTPRODUCT_ID NUMBER NOT NULL,
	   CONTRACTQMGROUP_ID NUMBER NOT NULL,
	   MAXCIRCULATINGINVENTORY NUMBER DEFAULT 0 NOT NULL,
	   MAXBILLINGQUANTITY NUMBER DEFAULT 0 NOT NULL,
	   MAXDELIVERYQUANTITY NUMBER DEFAULT 0 NOT NULL,
	   SYSTEMUSER_ID NUMBER NOT NULL,
	   TIMESTAMP DATE NOT NULL	   
);

ALTER TABLE CONTRACTPRODUCTQMGLIMIT ADD CONSTRAINT XPKCONTRACTPRODUCTQMGLIMIT_ID PRIMARY KEY (CONTRACTPRODUCTQMGLIMIT_ID);

CREATE UNIQUE INDEX XAK1CONTRACTPRODUCTQMGLIMIT ON CONTRACTPRODUCTQMGLIMIT(CONTRACTPRODUCT_ID ASC,CONTRACTQMGROUP_ID ASC);

ALTER TABLE CONTRACTPRODUCTQMGLIMIT ADD CONSTRAINT CPRODQMGLIMIT_CONTRACTPRODUCT FOREIGN KEY(CONTRACTPRODUCT_ID)
REFERENCES CONTRACTPRODUCT(CONTRACTPRODUCT_ID) ON DELETE CASCADE;

ALTER TABLE CONTRACTPRODUCTQMGLIMIT ADD CONSTRAINT CPRODQMGLIMIT_CONTRACTQMGROUP FOREIGN KEY(CONTRACTQMGROUP_ID)
REFERENCES CONTRACTQMGROUP(CONTRACTQMGROUP_ID) ON DELETE CASCADE;
