-- order 502893 (new Lotus order: 20010654.20) 


      /*
      ACTION is CREATE Table DEPARTMENTUSAGEDAY
      */

CREATE TABLE DEPARTMENTUSAGEDAY (
       DEPARTMENTUSAGEDAY_ID NUMBER NOT NULL,
       DEPARTMENT_ID        NUMBER NOT NULL,
       DAY_ID               NUMBER NOT NULL,
       USAGEDAY_ID          NUMBER NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL   
);


CREATE SEQUENCE SEQ_DEPARTMENTUSAGEDAY
START WITH 1
INCREMENT BY 1;


ALTER TABLE DEPARTMENTUSAGEDAY
       ADD  ( CONSTRAINT XPKDEPARTMENTUSAGEDAY PRIMARY KEY (
              DEPARTMENTUSAGEDAY_ID) ) ;


CREATE UNIQUE INDEX XAK1DEPARTMENTUSAGEDAY ON DEPARTMENTUSAGEDAY
(
       DEPARTMENT_ID                  ,
       DAY_ID                         ,
       USAGEDAY_ID                    
);


CREATE INDEX XIF1DEPARTMENTUSAGEDAY ON DEPARTMENTUSAGEDAY
(
       DEPARTMENT_ID                  ASC
);


CREATE INDEX XIF2DEPARTMENTUSAGEDAY ON DEPARTMENTUSAGEDAY
(
       DAY_ID                    ASC
);


CREATE INDEX XIF3DEPARTMENTUSAGEDAY ON DEPARTMENTUSAGEDAY
(
       USAGEDAY_ID                         ASC
);


ALTER TABLE DEPARTMENTUSAGEDAY
       ADD  ( CONSTRAINT DEPARTMENTUSAGEDAY_DAY_ID
              FOREIGN KEY (DAY_ID)
                             REFERENCES DAY ) ;


ALTER TABLE DEPARTMENTUSAGEDAY
       ADD  ( CONSTRAINT DEPARTMENTUSAGEDAY_USAGEDAY_ID
              FOREIGN KEY (USAGEDAY_ID)
                             REFERENCES DAY ) ;


ALTER TABLE DEPARTMENTUSAGEDAY
       ADD  ( CONSTRAINT DEPARTMENTUSAGEDAY_DEPARTMENT_
              FOREIGN KEY (DEPARTMENT_ID)
                             REFERENCES DEPARTMENT
                             ON DELETE CASCADE ) ;



