Amey B-50 DWM Lab Experiment-2
Amey B-50 DWM Lab Experiment-2
Amey B-50 DWM Lab Experiment-2
PART A
(PART A: TO BE REFERRED BY STUDENTS)
Experiment No.02
A.1 Aim:
Implementation of all dimension tables and fact tables related to the case
study mentioned in the first experiment.
A.2 Prerequisite:
Refer to the DBMS manual for SQL Commands and ER diagram.
A.3 Outcome:
After successful completion of this experiment students will be able to
design a data warehouse with dimension modelling.
A.4 Theory:
1
Algorithm:
1. Customer table
The CUSTOMER table is populated using the following sample DML statement
2. Item table
SQL>CREATE TABLE item
2 ( item_id VARCHAR2(20) PRIMARY KEY,
3 name VARCHAR2(20) NOT NULL,
4 brand VARCHAR2(20) NOT NULL,
5 dept NUMBER,
6 c_price NUMBER,
7 s_price NUMBER,
8 stock NUMBER);
SQL>INSERT INTO ITEM VALUES ( ‘R4CB84’, ’talc’ ,’ponds’, 5 ,28 ,34 , 21);
2
3. Trans Table
The TRANS table is populated using the following sample DML statement
SQL>INSERT INTO TRANS VALUES (‘R4T81’, ‘R4200’ ,’9-Jan-2003’, 47684, 4);
4. Item_sold Table
5. Branch Table
SQL>CREATE TABLE branch
2 ( branchid NUMBER(2) PRIMARY KEY ,
3 street VARCHAR2(54),
4 city VARCHAR2(54),
5 state VARCHAR2(54) );
3
IMPLEMENTATION OF ENTERPRISE DATAMART
4
CREATION OF FACT TABLE
1. Sales_fact table
SQL> CREATE TABLE sales_fact
2 (custid VARCHAR2 (20) REFERENCES customer(customer_id),
3 itemid VARCHAR2 (20) REFERENCES item(item_id),
4 branchid NUMBER REFERENCES branch(branchid) ,
5 timeid DATE, REFERENCES time(timeid)
6 qty NUMBER,
7 profit NUMBER) ;
5
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per the following segments within two hours
of the practical. The soft copy must be uploaded on the Blackboard or emailed to the
concerned lab in charge faculties at the end of the practical in case there is no
Blackboard access available)
Dimension Table
CUSTOMER
6
SELECT * FROM CUSTOMER
7
PRODUCT
8
CREATE TABLE PRODUCT
( PRODUCT_ID VARCHAR2(10) PRIMARY KEY,
PRODUCT_NAME VARCHAR2(40) NOT NULL,
PRODUCT_COST VARCHAR(10) );
9
STORE
10
( STORE_ID VARCHAR2(10) PRIMARY KEY,
STORE_NAME VARCHAR2(40) NOT NULL,
STORE_LOCATION VARCHAR(40),
STORE_CITY VARCHAR2(20),
STORE_STATE varchar2(20) );
INSERT INTO STORE VALUES ( 1, 'Star Bazaar, 'Korum Mall', 'Thane', 'Maharashtra');
INSERT INTO STORE VALUES ( 2, 'DMart', 'Ghodbunder Road', 'Thane',
'Maharashtra');
INSERT INTO STORE VALUES ( 3, 'Big Bazaar', 'High Street Mall', 'Thane',
'Maharashtra');
INSERT INTO STORE VALUES ( 4, 'Reliance Fresh', 'Naupada', 'Thane',
'Maharashtra');
INSERT INTO STORE VALUES ( 5,'Hyper City', 'Viviana Mall', 'Thane', 'Maharashtra');
11
SALESPERSON
12
( SALESPERSON_ID VARCHAR2(10) PRIMARY KEY,
SALESPERSON_NAME VARCHAR2(40) NOT NULL,
STORE_ID VARCHAR2(10),
LOCATION VARCHAR(20),
CITY VARCHAR2(10),
STATE VARCHAR2(20) );
13
SELECT * FROM SALESPERSON
14
Fact Table
15
CREATE TABLE PRODUCTSALES
( TRANSACTION_ID VARCHAR2(20) PRIMARY KEY,
INVOICE_NO VARCHAR2(10),
TOTAL_AMOUNT VARCHAR2(10),
CUSTOMER_ID VARCHAR2(10) REFERENCES CUSTOMER(CUSTOMER_ID),
PRODUCT_ID VARCHAR2(10) REFERENCES PRODUCT(PRODUCT_ID),
STORE_ID VARCHAR2(10) REFERENCES STORE(STORE_ID),
SALESPERSON_ID VARCHAR2(10) REFERENCES SALESPERSON(SALESPERSON_ID)
);
INSERT INTO PRODUCTSALES VALUES('1', '501', '1678', '4', '2,3,4', '5', '2');
16
B.2 Input and Output:
(Paste your program input and output in the following format, If there is an error then paste the
specific error in the output part. In case of an error with the due permission of the faculty, an
extension can be given to submit the error-free code with output in due course of time.
Students will be graded accordingly.)
Input :
SQL commands/script which satisfies Two different outcomes mentioned in
Problem statements.
Output:
1. Dimensional Tables created after firing the above SQL commands.
2. The output satisfies 2 different outcomes mentioned in Problem
statements.
B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed above
and learning/observation noted in section B.3)
The concept of a fact table and dimension table was implemented using
dimension modelling.
B.5 Question of Curiosity
(To be answered by the student based on the practical performed and learning/observations)
Q1: What are the differences between the Dimension table and the fact table?
17
Ans:
Parameters Fact Table Dimension Table
Definition Measurements, metrics or facts The companion table to the fact table
about a business process. contains descriptive attributes to be
used as query constraining.
Characteristic Located at the centre of a star or Connected to the fact table and located
snowflake schema and surrounded at the edges of the star or snowflake
by dimensions. schema
Design Defined by their grain or its most Should be wordy, descriptive, complete,
atomic level. and quality assured.
Type of Data Facts tables could contain Evert dimension table contains
information like sales against a set attributes that describe the details of
of dimensions like Product and the dimension. E.g., Product dimensions
Date. can contain Product ID, Product
Category, etc.
Key The primary Key in the fact table is The dimension table has primary key
mapped as foreign keys to columns that uniquely identifies each
Dimensions. dimension.
Storage Helps to store report labels and Load detailed atomic data into
filter domain values in dimension dimensional structures.
tables.
Q2: Explain Primary Keys, Surrogate Keys & Foreign Keys with an example.
Ans:
Primary key:
18
A column or group of columns in a table that helps us to uniquely identifies every
row in that table is called a primary key. This DBMS can't be a duplicate. The same
value can't appear more than once in the table.
Surrogate key:
An artificial key that aims to uniquely identify each record is called a surrogate key.
These kinds of keys are unique because they are created when you don't have any
natural primary key. They do not lend any meaning to the data in the table. The
surrogate key is usually an integer.
Foreign key:
A foreign key is a column that is added to create a relationship with another table.
Foreign keys help us to maintain data integrity and also allows navigation between
two different instances of an entity. Every relationship in the model needs to be
supported by a foreign key.
19