--order 502629     
      /*
      ACTION is CREATE Table CATALOGUETYPE
      */
CREATE SEQUENCE SEQ_CATALOGUETYPE
START WITH 1
INCREMENT BY 1;

CREATE TABLE CATALOGUETYPE (
       CATALOGUETYPE_ID     NUMBER NOT NULL,
       CODE                 VARCHAR2(6) NOT NULL,
       ACTIVE               VARCHAR2(1) DEFAULT 'Y' NOT NULL
                                   CONSTRAINT YN_ValidationNew184
                                          CHECK (ACTIVE IN ('Y', 'N')),
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE UNIQUE INDEX XAK1CATALOGUETYPE ON CATALOGUETYPE
(
       CODE                           
);

ALTER TABLE CATALOGUETYPE
       ADD  ( CONSTRAINT XPKCATALOGUETYPE PRIMARY KEY (
              CATALOGUETYPE_ID) ) ;

      
      /*
      ACTION is CREATE Table CATALOGUE
      */
CREATE SEQUENCE SEQ_CATALOGUE
START WITH 1
INCREMENT BY 1;

CREATE TABLE CATALOGUE (
       CATALOGUE_ID         NUMBER NOT NULL,
       CODE                 VARCHAR2(6) NOT NULL,
       CATALOGUETYPE_ID     NUMBER NOT NULL,
       STARTDATE            DATE DEFAULT sysdate NOT NULL,
       ENDDATE              DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE INDEX XIF1CATALOGUE ON CATALOGUE
(
       CATALOGUETYPE_ID               ASC
);

CREATE UNIQUE INDEX XAK1CATALOGUE ON CATALOGUE
(
       CODE                           
);

ALTER TABLE CATALOGUE
       ADD  ( CONSTRAINT XPKCATALOGUE PRIMARY KEY (CATALOGUE_ID) ) ;

      
      /*
      ACTION is CREATE Table CATALOGUE_DESC
      */

CREATE TABLE CATALOGUE_DESC (
       CATALOGUE_ID         NUMBER NOT NULL,
       LANGUAGE_ID          NUMBER NOT NULL,
       DESCRIPTION          VARCHAR2(30) NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE INDEX XIF1CATALOGUE_DESC ON CATALOGUE_DESC
(
       CATALOGUE_ID                   ASC
);

CREATE INDEX XIF2CATALOGUE_DESC ON CATALOGUE_DESC
(
       LANGUAGE_ID                    ASC
);


ALTER TABLE CATALOGUE_DESC
       ADD  ( CONSTRAINT XPKCATALOGUE_DESC PRIMARY KEY (CATALOGUE_ID, 
              LANGUAGE_ID) ) ;

      
      /*
      ACTION is CREATE Table CATALOGUETYPE_DESC
      */

CREATE TABLE CATALOGUETYPE_DESC (
       CATALOGUETYPE_ID     NUMBER NOT NULL,
       LANGUAGE_ID          NUMBER NOT NULL,
       DESCRIPTION          VARCHAR2(30) NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE INDEX XIF1CATALOGUETYPE_DESC ON CATALOGUETYPE_DESC
(
       CATALOGUETYPE_ID               ASC
);

CREATE INDEX XIF2CATALOGUETYPE_DESC ON CATALOGUETYPE_DESC
(
       LANGUAGE_ID                    ASC
);


ALTER TABLE CATALOGUETYPE_DESC
       ADD  ( CONSTRAINT XPKCATALOGUETYPE_DESC PRIMARY KEY (
              CATALOGUETYPE_ID, LANGUAGE_ID) ) ;

      
      /*
      ACTION is CREATE Table PRODUCTCATALOGUE
      */

CREATE TABLE PRODUCTCATALOGUE (
       PRODUCT_ID           NUMBER NOT NULL,
       CATALOGUE_ID         NUMBER NOT NULL,
       STARTDATE            DATE NOT NULL,
       ENDDATE              DATE NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE INDEX XIF1PRODUCTCATALOGUE ON PRODUCTCATALOGUE
(
       PRODUCT_ID                     ASC
);

CREATE INDEX XIF2PRODUCTCATALOGUE ON PRODUCTCATALOGUE
(
       CATALOGUE_ID                   ASC
);


ALTER TABLE PRODUCTCATALOGUE
       ADD  ( CONSTRAINT XPKPRODUCTCATALOGUE PRIMARY KEY (PRODUCT_ID, 
              CATALOGUE_ID) ) ;

      
ALTER TABLE CATALOGUE
       ADD  ( CONSTRAINT CATALOGUE_CATALOGUETYPE_ID
              FOREIGN KEY (CATALOGUETYPE_ID)
                             REFERENCES CATALOGUETYPE ) ;


ALTER TABLE CATALOGUE_DESC
       ADD  ( CONSTRAINT CATALOGUE_D_LANGUAGE_ID
              FOREIGN KEY (LANGUAGE_ID)
                             REFERENCES LANGUAGES ) ;


ALTER TABLE CATALOGUE_DESC
       ADD  ( CONSTRAINT CATALOGUE_D_CATALOGUE_ID
              FOREIGN KEY (CATALOGUE_ID)
                             REFERENCES CATALOGUE
                             ON DELETE CASCADE ) ;


ALTER TABLE CATALOGUETYPE_DESC
       ADD  ( CONSTRAINT CATALOGUETYPE_D_LANGUAGE_ID
              FOREIGN KEY (LANGUAGE_ID)
                             REFERENCES LANGUAGES ) ;


ALTER TABLE CATALOGUETYPE_DESC
       ADD  ( CONSTRAINT CATALOGUETYPE_D_CATALOGUETYPE_
              FOREIGN KEY (CATALOGUETYPE_ID)
                             REFERENCES CATALOGUETYPE
                             ON DELETE CASCADE ) ;


ALTER TABLE PRODUCTCATALOGUE
       ADD  ( CONSTRAINT PRODUCTCATALOGUE_CATALOGUE_ID
              FOREIGN KEY (CATALOGUE_ID)
                             REFERENCES CATALOGUE
                             ON DELETE CASCADE ) ;


ALTER TABLE PRODUCTCATALOGUE
       ADD  ( CONSTRAINT PRODUCTCATALOGUE_PRODUCT_ID
              FOREIGN KEY (PRODUCT_ID)
                             REFERENCES PRODUCT
                             ON DELETE CASCADE ) ;











