-- ABS-132370
----------- RAGREASON ----------- 
ALTER TABLE RAGREASON ADD (FILTERBYBU VARCHAR2(1) DEFAULT 'N' NOT NULL);

ALTER TABLE RAGREASON
  ADD CONSTRAINT CHK_RAGREASON_FILTERBYBU
  CHECK (FILTERBYBU IN ('Y', 'N'));
  
----------- BUSINESSUNITPERRAGREASON ----------- 
CREATE TABLE BUSINESSUNITPERRAGREASON
( BUSINESSUNIT_ID NUMBER NOT NULL,
  RAGREASON_ID    NUMBER NOT NULL,
  SYSTEMUSER_ID   NUMBER NOT NULL,
  TIMESTAMP       DATE NOT NULL);

ALTER TABLE BUSINESSUNITPERRAGREASON
  ADD CONSTRAINT XPKBUSINESSUNITPERRAGREASON PRIMARY KEY (BUSINESSUNIT_ID, RAGREASON_ID);
  
CREATE INDEX XIF1BUSINESSUNITPERRAGREASON ON BUSINESSUNITPERRAGREASON (BUSINESSUNIT_ID);
CREATE INDEX XIF2BUSINESSUNITPERRAGREASON ON BUSINESSUNITPERRAGREASON (RAGREASON_ID);
 
ALTER TABLE BUSINESSUNITPERRAGREASON
  ADD CONSTRAINT FK_BUSINESSUNITPERRAGREASON_BU FOREIGN KEY (BUSINESSUNIT_ID)
  REFERENCES BUSINESSUNIT (BUSINESSUNIT_ID);
ALTER TABLE BUSINESSUNITPERRAGREASON
  ADD CONSTRAINT FK_BUSINESSUNITPERRAGREASON_RR FOREIGN KEY (RAGREASON_ID)
  REFERENCES RAGREASON (RAGREASON_ID) ON DELETE CASCADE;
