/*==============================================================*/
/* DBMS name:      PostgreSQL 8                                 */
/* Created on:     15/12/2013 12:13:47                          */
/*==============================================================*/


DROP INDEX BILL_SALE_FK;

DROP INDEX CLIENT_BILL_FK;

DROP TABLE BILL CASCADE;

DROP INDEX CLIENT_PK;

DROP TABLE CLIENT CASCADE;

DROP INDEX ORDER_PROVIDER_FK;

DROP INDEX ORDER_PK;

DROP TABLE "ORDER" CASCADE;

DROP INDEX PRODUCTS_ORDER_FK;

DROP INDEX ORDER_PRODUCTS_FK;

DROP INDEX ORDER_PRODUCTS_PK;

DROP TABLE ORDER_PRODUCTS CASCADE;

DROP INDEX PRODUCT_PK;

DROP TABLE PRODUCT CASCADE;

DROP INDEX PROVIDER_PK;

DROP TABLE PROVIDER CASCADE;

DROP INDEX PROVIDER_PRODUCTS_FK;

DROP INDEX PRODUCTS_PROVIDER_FK;

DROP INDEX PROVIDER_PRODUCTS_PK;

DROP TABLE PROVIDER_PRODUCTS;

DROP INDEX SALE_USER_FK;

DROP INDEX CLIENT_SALE_FK;

DROP INDEX SALE_PK;

DROP TABLE SALE CASCADE;

DROP INDEX CART_PRODUCT_FK;

DROP INDEX SALE_CART_FK;

DROP INDEX SHOPPINGCART_PK;

DROP TABLE SHOPPINGCART CASCADE;

DROP INDEX USER_STORE_FK;

DROP INDEX STORE_PK;

DROP TABLE STORE CASCADE;

DROP INDEX STORE_PRODUCTS_FK;

DROP INDEX PRODUCTS_STORE_FK;

DROP INDEX STORE_PRODUCTS_PK;

DROP TABLE STORE_PRODUCTS CASCADE;

DROP INDEX STORE_PROVIDERS_FK;

DROP INDEX PROVIDERS_STORE_FK;

DROP INDEX STORE_PROVIDERS_PK;

DROP TABLE STORE_PROVIDERS CASCADE;

DROP INDEX STORE_SALES_FK;

DROP INDEX SALES_STORE_FK;

DROP INDEX STORE_SALES_PK;

DROP TABLE STORE_SALES CASCADE;

DROP INDEX USER_USERBOSS_FK;

DROP INDEX USER_PK;

DROP TABLE "USER" CASCADE;

DROP INDEX USERPRIVILEGES_PK;

DROP TABLE USERPRIVILEGES CASCADE;

DROP INDEX PRIVILEGES_USER_FK;

DROP INDEX USER_PRIVILEGES_FK;

DROP INDEX USER_PRIVILEGES_PK;

DROP TABLE USER_PRIVILEGES CASCADE;

DROP INDEX STORE_WAREHOUSES_FK;

DROP INDEX WAREHOUSE_PK;

DROP TABLE WAREHOUSE CASCADE;

/*==============================================================*/
/* Table: BILL                                                  */
/*==============================================================*/
CREATE TABLE BILL (
   CLIENT_ID            INT4                 NULL,
   SALE_ID              INT4                 NULL
);

/*==============================================================*/
/* Index: CLIENT_BILL_FK                                        */
/*==============================================================*/
CREATE  INDEX CLIENT_BILL_FK ON BILL (
CLIENT_ID
);

/*==============================================================*/
/* Index: BILL_SALE_FK                                          */
/*==============================================================*/
CREATE  INDEX BILL_SALE_FK ON BILL (
SALE_ID
);

/*==============================================================*/
/* Table: CLIENT                                                */
/*==============================================================*/
CREATE TABLE CLIENT (
   CLIENT_ID            SERIAL NOT NULL,
   CLIENT_NAME          VARCHAR(50)          NULL,
   FIRST                VARCHAR(50)          NULL,
   CLIENT_EMAIL         VARCHAR(50)          NULL,
   CLIENT_ADDRESS       VARCHAR(150)         NULL,
   CLIENT_PHONENUMBER   VARCHAR(20)          NULL,
   CONSTRAINT PK_CLIENT PRIMARY KEY (CLIENT_ID)
);

/*==============================================================*/
/* Index: CLIENT_PK                                             */
/*==============================================================*/
CREATE UNIQUE INDEX CLIENT_PK ON CLIENT (
CLIENT_ID
);

/*==============================================================*/
/* Table: "ORDER"                                               */
/*==============================================================*/
CREATE TABLE "ORDER" (
   ORDER_ID             SERIAL NOT NULL,
   PROVIDER_ID          INT4                 NULL,
   ORDER_PRODUCTS       VARCHAR(300)         NULL,
   CONSTRAINT PK_ORDER PRIMARY KEY (ORDER_ID)
);

/*==============================================================*/
/* Index: ORDER_PK                                              */
/*==============================================================*/
CREATE UNIQUE INDEX ORDER_PK ON "ORDER" (
ORDER_ID
);

/*==============================================================*/
/* Index: ORDER_PROVIDER_FK                                     */
/*==============================================================*/
CREATE  INDEX ORDER_PROVIDER_FK ON "ORDER" (
PROVIDER_ID
);

/*==============================================================*/
/* Table: ORDER_PRODUCTS                                        */
/*==============================================================*/
CREATE TABLE ORDER_PRODUCTS (
   PRODUCT_ID           INT4                 NOT NULL,
   ORDER_ID             INT4                 NOT NULL,
   ORDER_PRODUCTS_AMOUNT INT4                 NULL,
   ORDER_PRODUCTS_PRICE FLOAT8               NULL,
   CONSTRAINT PK_ORDER_PRODUCTS PRIMARY KEY (PRODUCT_ID, ORDER_ID)
);

/*==============================================================*/
/* Index: ORDER_PRODUCTS_PK                                     */
/*==============================================================*/
CREATE UNIQUE INDEX ORDER_PRODUCTS_PK ON ORDER_PRODUCTS (
PRODUCT_ID,
ORDER_ID
);

/*==============================================================*/
/* Index: ORDER_PRODUCTS_FK                                     */
/*==============================================================*/
CREATE  INDEX ORDER_PRODUCTS_FK ON ORDER_PRODUCTS (
ORDER_ID
);

/*==============================================================*/
/* Index: PRODUCTS_ORDER_FK                                     */
/*==============================================================*/
CREATE  INDEX PRODUCTS_ORDER_FK ON ORDER_PRODUCTS (
PRODUCT_ID
);

/*==============================================================*/
/* Table: PRODUCT                                               */
/*==============================================================*/
CREATE TABLE PRODUCT (
   PRODUCT_ID           SERIAL NOT NULL,
   PRODUCT_BARCODE      VARCHAR(20)          NULL,
   PRODUCT_NAME         VARCHAR(50)          NULL,
   PRODUCT_PRICE        FLOAT8               NULL,
   CONSTRAINT PK_PRODUCT PRIMARY KEY (PRODUCT_ID)
);

/*==============================================================*/
/* Index: PRODUCT_PK                                            */
/*==============================================================*/
CREATE UNIQUE INDEX PRODUCT_PK ON PRODUCT (
PRODUCT_ID
);

/*==============================================================*/
/* Table: PROVIDER                                              */
/*==============================================================*/
CREATE TABLE PROVIDER (
   PROVIDER_ID          SERIAL NOT NULL,
   PROVIDER_NAME        VARCHAR(50)          NULL,
   PROVIDER_ADDRESS     VARCHAR(150)         NULL,
   PROVIDER_EMAIL       VARCHAR(50)          NULL,
   PROVIDER_PHONENUMBER VARCHAR(20)          NULL,
   CONSTRAINT PK_PROVIDER PRIMARY KEY (PROVIDER_ID)
);

/*==============================================================*/
/* Index: PROVIDER_PK                                           */
/*==============================================================*/
CREATE UNIQUE INDEX PROVIDER_PK ON PROVIDER (
PROVIDER_ID
);

/*==============================================================*/
/* Table: PROVIDER_PRODUCTS                                     */
/*==============================================================*/
CREATE TABLE PROVIDER_PRODUCTS (
   PROVIDER_ID          INT4                 NOT NULL,
   PRODUCT_ID           INT4                 NOT NULL,
   PROVIDER_PRODUCTS_PRICE FLOAT8               NULL,
   CONSTRAINT PK_PROVIDER_PRODUCTS PRIMARY KEY (PROVIDER_ID, PRODUCT_ID)
);

/*==============================================================*/
/* Index: PROVIDER_PRODUCTS_PK                                  */
/*==============================================================*/
CREATE UNIQUE INDEX PROVIDER_PRODUCTS_PK ON PROVIDER_PRODUCTS (
PROVIDER_ID,
PRODUCT_ID
);

/*==============================================================*/
/* Index: PRODUCTS_PROVIDER_FK                                  */
/*==============================================================*/
CREATE  INDEX PRODUCTS_PROVIDER_FK ON PROVIDER_PRODUCTS (
PRODUCT_ID
);

/*==============================================================*/
/* Index: PROVIDER_PRODUCTS_FK                                  */
/*==============================================================*/
CREATE  INDEX PROVIDER_PRODUCTS_FK ON PROVIDER_PRODUCTS (
PROVIDER_ID
);

/*==============================================================*/
/* Table: SALE                                                  */
/*==============================================================*/
CREATE TABLE SALE (
   SALE_ID              SERIAL NOT NULL,
   CLIENT_ID            INT4                 NULL,
   USER_ID              INT4                 NULL,
   SALE_DATE            VARCHAR(50)          NULL,
   CONSTRAINT PK_SALE PRIMARY KEY (SALE_ID)
);

/*==============================================================*/
/* Index: SALE_PK                                               */
/*==============================================================*/
CREATE UNIQUE INDEX SALE_PK ON SALE (
SALE_ID
);

/*==============================================================*/
/* Index: CLIENT_SALE_FK                                        */
/*==============================================================*/
CREATE  INDEX CLIENT_SALE_FK ON SALE (
CLIENT_ID
);

/*==============================================================*/
/* Index: SALE_USER_FK                                          */
/*==============================================================*/
CREATE  INDEX SALE_USER_FK ON SALE (
USER_ID
);

/*==============================================================*/
/* Table: SHOPPINGCART                                          */
/*==============================================================*/
CREATE TABLE SHOPPINGCART (
   PRODUCT_ID           INT4                 NOT NULL,
   SALE_ID              INT4                 NOT NULL,
   PRODUCT_PRICE        FLOAT8               NULL,
   PRODUCT_AMOUNT       INT4                 NULL,
   CONSTRAINT PK_SHOPPINGCART PRIMARY KEY (PRODUCT_ID, SALE_ID)
);

/*==============================================================*/
/* Index: SHOPPINGCART_PK                                       */
/*==============================================================*/
CREATE UNIQUE INDEX SHOPPINGCART_PK ON SHOPPINGCART (
PRODUCT_ID,
SALE_ID
);

/*==============================================================*/
/* Index: SALE_CART_FK                                          */
/*==============================================================*/
CREATE  INDEX SALE_CART_FK ON SHOPPINGCART (
SALE_ID
);

/*==============================================================*/
/* Index: CART_PRODUCT_FK                                       */
/*==============================================================*/
CREATE  INDEX CART_PRODUCT_FK ON SHOPPINGCART (
PRODUCT_ID
);

/*==============================================================*/
/* Table: STORE                                                 */
/*==============================================================*/
CREATE TABLE STORE (
   STORE_ID             SERIAL NOT NULL,
   USER_OWNER           INT4                 NULL,
   STORE_NAME           VARCHAR(50)          NULL,
   STORE_FIRSTNAME      VARCHAR(50)          NULL,
   STORE_EMAIL          VARCHAR(50)          NULL,
   STORE_ADDRESS        VARCHAR(150)         NULL,
   STORE_PHONENUMBER    VARCHAR(20)          NULL,
   CONSTRAINT PK_STORE PRIMARY KEY (STORE_ID)
);

/*==============================================================*/
/* Index: STORE_PK                                              */
/*==============================================================*/
CREATE UNIQUE INDEX STORE_PK ON STORE (
STORE_ID
);

/*==============================================================*/
/* Index: USER_STORE_FK                                         */
/*==============================================================*/
CREATE  INDEX USER_STORE_FK ON STORE (
USER_OWNER
);

/*==============================================================*/
/* Table: STORE_PRODUCTS                                        */
/*==============================================================*/
CREATE TABLE STORE_PRODUCTS (
   STORE_ID             INT4                 NOT NULL,
   PRODUCT_ID           INT4                 NOT NULL,
   STORE_PRODUCT_STOCK  INT4                 NULL,
   CONSTRAINT PK_STORE_PRODUCTS PRIMARY KEY (STORE_ID, PRODUCT_ID)
);

/*==============================================================*/
/* Index: STORE_PRODUCTS_PK                                     */
/*==============================================================*/
CREATE UNIQUE INDEX STORE_PRODUCTS_PK ON STORE_PRODUCTS (
STORE_ID,
PRODUCT_ID
);

/*==============================================================*/
/* Index: PRODUCTS_STORE_FK                                     */
/*==============================================================*/
CREATE  INDEX PRODUCTS_STORE_FK ON STORE_PRODUCTS (
PRODUCT_ID
);

/*==============================================================*/
/* Index: STORE_PRODUCTS_FK                                     */
/*==============================================================*/
CREATE  INDEX STORE_PRODUCTS_FK ON STORE_PRODUCTS (
STORE_ID
);

/*==============================================================*/
/* Table: STORE_PROVIDERS                                       */
/*==============================================================*/
CREATE TABLE STORE_PROVIDERS (
   STORE_ID             INT4                 NOT NULL,
   PROVIDER_ID          INT4                 NOT NULL,
   CONSTRAINT PK_STORE_PROVIDERS PRIMARY KEY (STORE_ID, PROVIDER_ID)
);

/*==============================================================*/
/* Index: STORE_PROVIDERS_PK                                    */
/*==============================================================*/
CREATE UNIQUE INDEX STORE_PROVIDERS_PK ON STORE_PROVIDERS (
STORE_ID,
PROVIDER_ID
);

/*==============================================================*/
/* Index: PROVIDERS_STORE_FK                                    */
/*==============================================================*/
CREATE  INDEX PROVIDERS_STORE_FK ON STORE_PROVIDERS (
PROVIDER_ID
);

/*==============================================================*/
/* Index: STORE_PROVIDERS_FK                                    */
/*==============================================================*/
CREATE  INDEX STORE_PROVIDERS_FK ON STORE_PROVIDERS (
STORE_ID
);

/*==============================================================*/
/* Table: STORE_SALES                                           */
/*==============================================================*/
CREATE TABLE STORE_SALES (
   STORE_ID             INT4                 NOT NULL,
   SALE_ID              INT4                 NOT NULL,
   CONSTRAINT PK_STORE_SALES PRIMARY KEY (STORE_ID, SALE_ID)
);

/*==============================================================*/
/* Index: STORE_SALES_PK                                        */
/*==============================================================*/
CREATE UNIQUE INDEX STORE_SALES_PK ON STORE_SALES (
STORE_ID,
SALE_ID
);

/*==============================================================*/
/* Index: SALES_STORE_FK                                        */
/*==============================================================*/
CREATE  INDEX SALES_STORE_FK ON STORE_SALES (
SALE_ID
);

/*==============================================================*/
/* Index: STORE_SALES_FK                                        */
/*==============================================================*/
CREATE  INDEX STORE_SALES_FK ON STORE_SALES (
STORE_ID
);

/*==============================================================*/
/* Table: "USER"                                                */
/*==============================================================*/
CREATE TABLE "USER" (
   USER_ID              SERIAL NOT NULL,
   USER_BOSS_ID         INT4                 NULL,
   USER_NAME            VARCHAR(50)          NULL,
   USER_NICKNAME        VARCHAR(50)          NULL,
   USER_EMAIL           VARCHAR(50)          NULL,
   USER_LICENSENUMBER   VARCHAR(50)          NULL,
   USER_PASSWORD        VARCHAR(50)          NULL,
   CONSTRAINT PK_USER PRIMARY KEY (USER_ID)
);

/*==============================================================*/
/* Index: USER_PK                                               */
/*==============================================================*/
CREATE UNIQUE INDEX USER_PK ON "USER" (
USER_ID
);

/*==============================================================*/
/* Index: USER_USERBOSS_FK                                      */
/*==============================================================*/
CREATE  INDEX USER_USERBOSS_FK ON "USER" (
USER_BOSS_ID
);

/*==============================================================*/
/* Table: USERPRIVILEGES                                        */
/*==============================================================*/
CREATE TABLE USERPRIVILEGES (
   PRIVILEGE_ID         SERIAL NOT NULL,
   PRIVILEGE_ACCESIBLEAREAS VARCHAR(80)          NULL,
   CONSTRAINT PK_USERPRIVILEGES PRIMARY KEY (PRIVILEGE_ID)
);

/*==============================================================*/
/* Index: USERPRIVILEGES_PK                                     */
/*==============================================================*/
CREATE UNIQUE INDEX USERPRIVILEGES_PK ON USERPRIVILEGES (
PRIVILEGE_ID
);

/*==============================================================*/
/* Table: USER_PRIVILEGES                                       */
/*==============================================================*/
CREATE TABLE USER_PRIVILEGES (
   PRIVILEGE_ID         INT4                 NOT NULL,
   USER_ID              INT4                 NOT NULL,
   CONSTRAINT PK_USER_PRIVILEGES PRIMARY KEY (PRIVILEGE_ID, USER_ID)
);

/*==============================================================*/
/* Index: USER_PRIVILEGES_PK                                    */
/*==============================================================*/
CREATE UNIQUE INDEX USER_PRIVILEGES_PK ON USER_PRIVILEGES (
PRIVILEGE_ID,
USER_ID
);

/*==============================================================*/
/* Index: USER_PRIVILEGES_FK                                    */
/*==============================================================*/
CREATE  INDEX USER_PRIVILEGES_FK ON USER_PRIVILEGES (
USER_ID
);

/*==============================================================*/
/* Index: PRIVILEGES_USER_FK                                    */
/*==============================================================*/
CREATE  INDEX PRIVILEGES_USER_FK ON USER_PRIVILEGES (
PRIVILEGE_ID
);

/*==============================================================*/
/* Table: WAREHOUSE                                             */
/*==============================================================*/
CREATE TABLE WAREHOUSE (
   WAREHOUSE_ID         SERIAL NOT NULL,
   STORE_ID             INT4                 NULL,
   WAREHOUSE__NAME      VARCHAR(50)          NULL,
   WAREHOUSE_DESCRIPTION VARCHAR(300)         NULL,
   WAREHOUSE_CAPACITY   INT4                 NULL,
   CONSTRAINT PK_WAREHOUSE PRIMARY KEY (WAREHOUSE_ID)
);

/*==============================================================*/
/* Index: WAREHOUSE_PK                                          */
/*==============================================================*/
CREATE UNIQUE INDEX WAREHOUSE_PK ON WAREHOUSE (
WAREHOUSE_ID
);

/*==============================================================*/
/* Index: STORE_WAREHOUSES_FK                                   */
/*==============================================================*/
CREATE  INDEX STORE_WAREHOUSES_FK ON WAREHOUSE (
STORE_ID
);

ALTER TABLE BILL
   ADD CONSTRAINT FK_BILL_BILL_SALE_SALE FOREIGN KEY (SALE_ID)
      REFERENCES SALE (SALE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE BILL
   ADD CONSTRAINT FK_BILL_CLIENT_BI_CLIENT FOREIGN KEY (CLIENT_ID)
      REFERENCES CLIENT (CLIENT_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE "ORDER"
   ADD CONSTRAINT FK_ORDER_ORDER_PRO_PROVIDER FOREIGN KEY (PROVIDER_ID)
      REFERENCES PROVIDER (PROVIDER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE ORDER_PRODUCTS
   ADD CONSTRAINT FK_ORDER_PR_ORDER_PRO_ORDER FOREIGN KEY (ORDER_ID)
      REFERENCES "ORDER" (ORDER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE ORDER_PRODUCTS
   ADD CONSTRAINT FK_ORDER_PR_PRODUCTS__PRODUCT FOREIGN KEY (PRODUCT_ID)
      REFERENCES PRODUCT (PRODUCT_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE PROVIDER_PRODUCTS
   ADD CONSTRAINT FK_PROVIDER_PRODUCTS__PRODUCT FOREIGN KEY (PRODUCT_ID)
      REFERENCES PRODUCT (PRODUCT_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE PROVIDER_PRODUCTS
   ADD CONSTRAINT FK_PROVIDER_PROVIDER__PROVIDER FOREIGN KEY (PROVIDER_ID)
      REFERENCES PROVIDER (PROVIDER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE SALE
   ADD CONSTRAINT FK_SALE_CLIENT_SA_CLIENT FOREIGN KEY (CLIENT_ID)
      REFERENCES CLIENT (CLIENT_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE SALE
   ADD CONSTRAINT FK_SALE_SALE_USER_USER FOREIGN KEY (USER_ID)
      REFERENCES "USER" (USER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE SHOPPINGCART
   ADD CONSTRAINT FK_SHOPPING_CART_PROD_PRODUCT FOREIGN KEY (PRODUCT_ID)
      REFERENCES PRODUCT (PRODUCT_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE SHOPPINGCART
   ADD CONSTRAINT FK_SHOPPING_SALE_CART_SALE FOREIGN KEY (SALE_ID)
      REFERENCES SALE (SALE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE
   ADD CONSTRAINT FK_STORE_USER_STOR_USER FOREIGN KEY (USER_OWNER)
      REFERENCES "USER" (USER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE_PRODUCTS
   ADD CONSTRAINT FK_STORE_PR_PRODUCTS__PRODUCT FOREIGN KEY (PRODUCT_ID)
      REFERENCES PRODUCT (PRODUCT_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE_PRODUCTS
   ADD CONSTRAINT FK_STORE_PR_STORE_PRO_STORE FOREIGN KEY (STORE_ID)
      REFERENCES STORE (STORE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE_PROVIDERS
   ADD CONSTRAINT FK_STORE_PR_PROVIDERS_PROVIDER FOREIGN KEY (PROVIDER_ID)
      REFERENCES PROVIDER (PROVIDER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE_PROVIDERS
   ADD CONSTRAINT FK_STORE_PR_STORE_PRO_STORE FOREIGN KEY (STORE_ID)
      REFERENCES STORE (STORE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE_SALES
   ADD CONSTRAINT FK_STORE_SA_SALES_STO_SALE FOREIGN KEY (SALE_ID)
      REFERENCES SALE (SALE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE STORE_SALES
   ADD CONSTRAINT FK_STORE_SA_STORE_SAL_STORE FOREIGN KEY (STORE_ID)
      REFERENCES STORE (STORE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE "USER"
   ADD CONSTRAINT FK_USER_USER_USER_USER FOREIGN KEY (USER_BOSS_ID)
      REFERENCES "USER" (USER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE USER_PRIVILEGES
   ADD CONSTRAINT FK_USER_PRI_PRIVILEGE_USERPRIV FOREIGN KEY (PRIVILEGE_ID)
      REFERENCES USERPRIVILEGES (PRIVILEGE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE USER_PRIVILEGES
   ADD CONSTRAINT FK_USER_PRI_USER_PRIV_USER FOREIGN KEY (USER_ID)
      REFERENCES "USER" (USER_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE WAREHOUSE
   ADD CONSTRAINT FK_WAREHOUS_STORE_WAR_STORE FOREIGN KEY (STORE_ID)
      REFERENCES STORE (STORE_ID)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

