Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DWM Exp 2 C49

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

LAB Manual

PART A
(PART A : TO BE REFFERED BY STUDENTS)

Experiment No.02

A.1 Aim:
Implementation of all dimension tables and fact tables related to case
study mentioned in first experiment.
A.2 Prerequisite:
Refer the DBMS manual for SQL Commands and ER diagram.
A.3 Outcome:
After successful completion of this experiment students will be
able to
Model and create schemas for data warehouse.

A.4 Theory:

Dimensions are categories by which summarized data can be viewed. E.g.


a profit summary in a fact table can be viewed by a Time dimension (profit
by month, quarter, year), Region dimension (profit by country, state, city),
Product dimension (profit for product1, product2).
A fact table is a table that contains summarized numerical and historical
data (facts) and a multipart index composed of foreign keys from the
primary keys of related dimension tables.
In data warehousing, a dimension is a collection of reference information
about a measurable event. These events are known as facts and are
stored in a fact table. Dimensions categorize and describe data warehouse
facts and measures in ways that support meaningful answers to business
questions. They form the very core of dimensional modeling.
Dimension tables are referenced by fact tables using keys. When creating
a dimension table in a data warehouse, a system-generated key is used to
uniquely identify a row in the dimension. This key is also known as a
surrogate key. The surrogate key is used as the primary key in the
dimension table. The surrogate key is placed in the fact table and a
foreign key is defined between the two tables. When the data is joined, it
does so just as any other join within the database.

Algorithm:
CREATION OF OLTP TABLES
1) Customer table
SQL>CREATE TABLE customer
2 ( customer_id VARCHAR2(10) PRIMARY KEY,
3 name VARCHAR2(40) NOT NULL,
4 addr VARCHAR2(10) NOT NULL,
5 dob DATE,
6 in_range NUMBER,
7 h_owner NUMBER,
8 c_owner NUMBER );
The CUSTOMER table is populated using the following sample DML
statemen

SQL>INSERT INTO CUSTOMER VALUES (‘R41’, ‘Devarsee


banerjee’ ,Chennai’,
’16-dec-1947’ , 1 ,0 ,1);

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,
1) 8 stock NUMBER); Item
table

The ITEM table is populated using the sample DML statement

SQL>INSERT INTO ITEM VALUES ( ‘R4CB84’, ’talc’ ,’ponds’, 5 ,28


,34 , 21);

3) Trans table
SQL>CREATE TABLE trans
2 ( transid VARCHAR2(20) PRIMARY KEY,
3 custid VARCHAR2(20) REFERENCES
4 customer (customer_id),
5 datet DATE,
6 amt NUMBER,
7 branchid NUMBER(2) );

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
SQL> CREATE TABLE item_sold
2 ( transid VARCHAR2(20) REFERENCES
trans(transid),
3 itemid VARCHAR2(20) REFERENCES
item(item_id),
4 qty NUMBER);

The ITEM_SOLD table is populated using the following DML statement


SQL>INSERT INTO ITEM_SOLD VALUES (‘R4T996’, ‘R4SP16’ ,3);

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) );
The BRANCH table is populated using the following DML statement
SQL>INSERT INTO BRANCH VALUES ( ‘Prasad’,
‘Banglore’ ,‘karnataka’ );

IMPLEMENTATION OF ENTERPRISE DATAMART

CREATION OF DIMENSION TABLES

1) Customer dimension table


SQL> CREATE TABLE customer
2 ( customer_id NUMBER PRIMARY KEY,
3 name VARCHAR2(40) NOT NULL,
4 addr VARCHAR2(10) NOT NULL,
5 dob DATE,
6 in_range NUMBER,
7 h_owner NUMBER,
8 c_owner NUMBER);

2) Item dimension table


SQL> CREATE TABLE item
2 ( item_id NUMBER 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);

3) Branch dimension table


SQL> CREATE TABLE branch
2 (branchid NUMBER PRIMARY KEY,
3 street VARCHAR2(54),
4 city VARCHAR2(54),
5 state VARCHAR2(54));

4) Time dimension table


SQL> CREATE TABLE time
2 ( timeid NUMBER PRIMARY KEY,
3 day VARCHAR2(3),
4 month VARCHAR2(4),
5 year VARCHAR2(3));

CREATION OF FACT TABLE


1) Sales_fact table

SQL> CREATE TABLE sales_fact


2 (custid NUMBER REFERENCES customer(customer_id),
3 itemid NUMBER REFERENCES item(item_id),
4 branchid NUMBER REFERENCES branch(branchid) ,
5 timeid NUMBER REFERENCES time(timeid)
6 qty NUMBER,
7 profit NUMBER) ;

PART B
PART B :
(TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per 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 the there is no Black
board access available)
B.1 Software Code written by student:
(Paste your sql script completed during the 2 hours of practical in
the lab here)

Dimension Table

CUSTOMER
CREATE TABLE CUSTOMER
( CUSTOMER_ID VARCHAR2(10) PRIMARY KEY,
NAME VARCHAR2(40) NOT NULL,
GENDER VARCHAR(10) );

INSERT INTO CUSTOMER VALUES ( 1, 'Archit Konde', 'MALE');


INSERT INTO CUSTOMER VALUES ( 2, 'Saakshi Deokar', 'FEMALE');
INSERT INTO CUSTOMER VALUES ( 3, 'Hasan Rizvi', 'MALE');
INSERT INTO CUSTOMER VALUES ( 4, 'Mega Modha', 'FEMALE');
INSERT INTO CUSTOMER VALUES ( 5, 'Mayuresh Phansikar', 'MALE');
INSERT INTO CUSTOMER VALUES ( 6, 'Injila Hussain', 'FEMALE');
SELECT * FROM CUSTOMER
PRODUCT

CREATE TABLE PRODUCT


( PRODUCT_ID VARCHAR2(10) PRIMARY KEY,
PRODUCT_NAME VARCHAR2(40) NOT NULL,
PRODUCT_COST VARCHAR(10) );

INSERT INTO PRODUCT VALUES ( 1, 'Cadbury Dairy Milk Silk', '140');


INSERT INTO PRODUCT VALUES ( 2, 'Nestle Kit Kat White', '380');
INSERT INTO PRODUCT VALUES ( 3, 'Twix Miniature', '449');
INSERT INTO PRODUCT VALUES ( 4, 'Ferrero Rocher Truffles', '849');
INSERT INTO PRODUCT VALUES ( 5, 'Toblerone Dark Bar', '1299');
INSERT INTO PRODUCT VALUES ( 6, 'Galaxy Smooth Milk', '300');
SELECT * FROM PRODUCT
STORE

CREATE TABLE STORE


( 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');
SELECT * FROM STORE
SALESPERSON

CREATE TABLE SALESPERSON


( 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) );
INSERT INTO SALESPERSON VALUES ( 1 , 'Supreet', 1, 'Korum Mall', 'Thane',
'Maharahstra');
INSERT INTO SALESPERSON VALUES ( 2 , 'Filly', 1, 'Korum Mall', 'Thane',
'Maharahstra');
INSERT INTO SALESPERSON VALUES ( 3 , 'Saiganesh', 2, 'Ghodbunder Road',
'Thane', 'Maharahstra');
INSERT INTO SALESPERSON VALUES ( 4 , 'Saurabh', 3, 'High Street Mall',
'Thane', 'Maharahstra');
INSERT INTO SALESPERSON VALUES ( 5 , 'Sakshi', 3, 'High Street Mall', 'Thane',
'Maharahstra');
INSERT INTO SALESPERSON VALUES ( 6 , 'Hemant', 4, 'Naupada', 'Thane',
'Maharahstra');
INSERT INTO SALESPERSON VALUES ( 7 , 'Rutika', 5, 'Viviana Mall', 'Thane',
'Maharahstra');
SELECT * FROM SALESPERSON
Fact Table

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');
SELECT * FROM PRODUCTSALES;

B.2 Input and Output:


(Paste your program input and output in following format, If
there is error then paste the specific error in the output part. In
case of error with due permission of the faculty extension can be
given to submit the error free code with output in due course of
time. Students will be graded accordingly.)
Note: Input and Output are mentioned in section B.1
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.3 Observations and learning:
(Students are expected to comment on the output obtained with
clear observations and learning for each task/ sub part assigned)
A dimensional model is a data structure technique optimized
for Data warehousing tools. The concept of Dimensional Modelling is comprised of
"fact" and "dimension" tables. These dimensional and relational models have their
unique way of data storage that has specific advantages.
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 student based on the practical performed and
learning/observations)
Q1: What are the differences between the Dimension table and the fact table?
Ans:

Q2: Explain Primary Keys, Surrogate Keys & Foreign Keys with an example.
Ans:
Primary key:
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.

You might also like