-
Notifications
You must be signed in to change notification settings - Fork 9
/
createDW.sql
69 lines (61 loc) · 1.87 KB
/
createDW.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--star schema DW--
--Drop the table(s) if exist in the database--
--Drop fact_sale--
DROP TABLE FACT_SALE;
--Drop dimension tables--
DROP TABLE DIM_PRODUCT;
DROP TABLE DIM_STORE;
DROP TABLE DIM_CUSTOMER;
DROP TABLE DIM_SUPPLIER;
DROP TABLE DIM_DATE;
--Create dimension tables--
CREATE TABLE DIM_PRODUCT
(
PRODUCT_ID VARCHAR2(6),
PRODUCT_NAME VARCHAR2(30) NOT NULL,
CONSTRAINT PRODUCT_PK PRIMARY KEY (PRODUCT_ID)
);
CREATE TABLE DIM_STORE
(
STORE_ID VARCHAR2(4),
STORE_NAME VARCHAR2(20) NOT NULL,
CONSTRAINT STORE_PK PRIMARY KEY (STORE_ID)
);
CREATE TABLE DIM_CUSTOMER
(
CUSTOMER_ID VARCHAR2(4),
CUSTOMER_NAME VARCHAR2(30),
CONSTRAINT CUSTOMER_PK PRIMARY KEY (CUSTOMER_ID)
);
CREATE TABLE DIM_SUPPLIER
(
SUPPLIER_ID VARCHAR2(5),
SUPPLIER_NAME VARCHAR2(30),
CONSTRAINT SUPPLIER_PK PRIMARY KEY (SUPPLIER_ID)
);
CREATE TABLE DIM_DATE
(
T_CDATE VARCHAR2(8 BYTE),
T_DATE DATE,
T_YEAR NUMBER(10,0),
T_QUARTER NUMBER(10,0),
T_MONTH CHAR(10 BYTE),
T_DAY NUMBER(10,0),
CONSTRAINT date_pk PRIMARY KEY (T_DATE)
);
CREATE TABLE FACT_SALE
(
CUSTOMER_ID VARCHAR2(4),
STORE_ID VARCHAR2(4),
SUPPLIER_ID VARCHAR2(5),
PRODUCT_ID VARCHAR2(6),
TOTAL_SALE NUMBER(5,2),
T_DATE DATE,
PRICE NUMBER(5,2) DEFAULT 0.0,
QUANTITY NUMBER(3,0) DEFAULT 0.0,
CONSTRAINT SALE_STORE_FK FOREIGN KEY (STORE_ID) REFERENCES DIM_STORE (STORE_ID),
CONSTRAINT SALE_SUPPLIER_FK FOREIGN KEY (SUPPLIER_ID) REFERENCES DIM_SUPPLIER (SUPPLIER_ID),
CONSTRAINT SALE_PRODUCT_FK FOREIGN KEY (PRODUCT_ID) REFERENCES DIM_PRODUCT (PRODUCT_ID),
CONSTRAINT SALE_DATE_FK FOREIGN KEY (T_DATE) REFERENCES DIM_DATE (T_DATE),
CONSTRAINT SALE_CUSTOMER_FK FOREIGN KEY (CUSTOMER_ID) REFERENCES DIM_CUSTOMER (CUSTOMER_ID)
);