Docsity

Creating Databases-Data Warehouse-Lab Mannual, Lecture notes of Data Warehousing

Partial preview of the text

Download Creating Databases-Data Warehouse-Lab Mannual and more Lecture notes Data Warehousing in PDF only on Docsity!

Today Lab Objectives

  • Creating a Database User ID in MYSQL
  • Creating Data base in MYSQL
  • Creating Fact and dimensions Tables

www.company.com

  • Data insertion in Tables
  • Generating Surrogate Keys

Creating a Database User ID

  • Open Command prompt
  • Set the directory where MYSQL is installed
  • Write the command

mysql – u root – p

www.company.com

mysql – u root – p

  • You’ll be prompted to enter the password.
  • Enter password: ********
  • If you have entered a correct password you will see a response like this
  • Welcome to the MySQL monitor. Commands end with ; or \g.

Show Grants command

  • mysql> show grants for userid@localhost;
  • Result of show grants
    • Grants for userid@localhostGRANT ALL PRIVILEGES ON . TO ‘userid'@'localhost' IDENTIFIED

www.company.com

ON . TO ‘userid'@'localhost' IDENTIFIED BYPASSWORD '*D821809F681A40A6E379B50D0463EFAE20BDD12‘

  • 1 row in set (0.00 sec)
  • Now log out by writing the following command
  • exit

Log on as userid

  • To log on as userid , use this command:
    • mysql -udwid –p
  • Then, enter the password for userid. Remember

the password is yourpassword.

www.company.com

the password is yourpassword.

Creating Data Bases (1)

sql commands for creating DB

  • CREATE DATABASE source;
  • CREATE DATABASE dw;

www.company.com

On your console, you’ll see

  • Query OK, 1 row affected (0.00 sec)
  • Query OK, 1 row affected (0.00 sec)

Show database command

  • mysql> show databases like 'dw‘; The response should look something like the following. +---------------+ | Database (dw) | +---------------+ | dw |

www.company.com

| dw | +---------------+ 1 row in set (0.00 sec)

  • mysql> show databases like 'source'; The response should be +-------------------+ Database (source) | +-------------------+ | source | +-------------------+ 1 row in set (0.00 sec)

Creating Dimension Table

  • CREATE TABLE customer_dim ( customer_sk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, customer_number INT, customer_name CHAR (50), customer_street_address CHAR ( 50 ),

www.company.com

customer_street_address CHAR ( 50 ), customer_zip_code INT (5), customer_city CHAR (30), customer_state CHAR (2), effective_date DATE, expiry_date DATE ); After running this command You’ll see something similar to this on your console: Database changed Query OK, 0 rows affected

Creating Dimension Table(1)

  • CREATE TABLE product_dim

( product_sk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, product_code INT, product_name CHAR ( 30 ), product_category

www.company.com

product_name CHAR ( 30 ), product_category CHAR (30), effective_date DATE, expiry_date DATE );

After running this command You’ll see something

similar to this on your console:

Database changed

Query OK, 0 rows affected

Creating Dimension Table(3)

  • CREATE TABLE date_dim

( date_sk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, date DATE, month_name CHAR ( 9 ), month INT ( 1 ), quarter INT ( 1 ), year

www.company.com

CHAR ( 9 ), month INT ( 1 ), quarter INT ( 1 ), year INT (4), effective_date DATE, expiry_date DATE );

After running this command You’ll see something

similar to this on your console:

Database changed

Query OK, 0 rows affected

Creating Fact Table

  • CREATE TABLE sales_order_fact

( order_sk INT, customer_sk INT, product_sk INT,

order_date_sk INT, order_amount DECIMAL ( 10 , 2 ) );

www.company.com

After running this command You’ll see something

similar to this on your console:

Database changed

Query OK, 0 rows affected

Show Create table command.

  • On you console, you’ll see **************** 1. row ******************* Table: customer_dim Create Table: CREATE TABLE 'customer_dim' ( 'customer_sk'^ int(11) NOT NULL auto_increment, 'customer_number'^ int(11) default NULL, 'customer_name' char ( 50 ) default NULL,

www.company.com

'customer_name' char ( 50 ) default NULL, 'customer_street_address' char (50) default NULL, 'customer_zip_code' int (5) default NULL, 'customer_city' char (30) default NULL, ‘customer_state' char (2) default NULL, 'effective_date' date default NULL, 'expiry_date' date default NULL, PRIMARY KEY ('customer_sk') ) ENGINE=InnoDB DEFAULT CHARSET=latin 1 row in set (0.00 sec) Using the same command, you can verify the other four tables were created successfully.

Generating Surrogate Keys

  • USE dw;
  • INSERT INTO customer_dim( customer_sk, customer_number, customer_name, customer_street_address, customer_zip_code, customer_city,customer_state,effective_date,

www.company.com

customer_city,customer_state,effective_date, expiry_date) VALUES (NULL, 1, 'Big Customers' , '7500 Louise Dr.', '17050', 'Mechanicsburg', 'PA', CURRENT_DATE, '9999-12-31'), (NULL, 2, 'Small Stores', '2500 Woodland St.', '17055', 'Pittsburgh', 'PA', CURRENT_DATE, '9999-12-31'), (NULL, 3, 'Medium Retailers', '1111 Ritter Rd.', '17055' , 'Pittsburgh', 'PA', CURRENT_DATE, '9999-12-31');

Conforming surrogate keys Insertion

  • mysql> select * from customer_dim \G **************** 1. row ******************* customer_sk: 1 customer_number: 1

www.company.com

customer_number: 1 customer_name: Big Customerscustomer_street_address: 7500 Louise Dr. customer_zip_code: 17050 customer_city: Mechanicsburg customer_state: PA effective_date: 2010-09- expiry_date: 9999-12-

Surrogate keys Insertion (1)

**************** 2. row ******************* customer_sk: 2 customer_number: 2 customer_name: Small Stores

www.company.com

customer_name: Small Stores customer_street_address: 2500 Woodland St. customer_zip_code: 17055 customer_city: Pittsburgh customer_state: PA effective_date: 2010-09- expiry_date: 9999-12-