Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dear all your solution is incorrect,please check my solution below and edit the code, I think my issue is the connection between diemansions tables and

Dear all
your solution is incorrect,please check my solution below and edit the code, I think my issue is the connection between diemansions tables and fact table, because there is no data appear in Q7 until Q11.
----------------
-- Project Tasks:
--STEP 1: Create T_SALESMAN Table:
CREATE TABLE T_SALESMAN (
SALES_REP_ID NUMBER,
SNAME VARCHAR2(50)
);
SELECT DISTINCT COALESCE(SALES_REP_ID,999) AS SALES_REP_ID, 'NAME-'|| COALESCE(SALES_REP_ID,999) AS SNAME
FROM ORDERS_COPY;
--------------------------------------------
--Project3 Tasks:
---Q2 : Create all DIMENSION AS MATERIALIZED VIEWS.
--------1: Define a materialized View for D_TIME Dimension table.
CREATE MATERIALIZED VIEW MV_D_TIME
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
AS
SELECT
ROW_NUMBER() OVER (ORDER BY ORDER_DATE) AS ID_T,--generate a unique ID for each row based on ORDER_DATE
MONTH_NO,
QUARTER,
YYear AS YEAR,
ORDER_DATE AS ORDER_DATE,
Month_Name
FROM T_DATE
-- Display the content of the materialized view
SELECT * FROM MV_D_TIME;
--1.2: Define the D_TIME dimension using its created MV.
CREATE TABLE D_TIME AS
SELECT DISTINCT
ID_T,
MONTH_NO,
QUARTER,
YEAR,
ORDER_DATE,
MONTH_NAME
FROM MV_D_TIME;
-- Add a primary key constraint to the D_TIME table
ALTER TABLE D_TIME
ADD CONSTRAINT PK_D_TIME PRIMARY KEY (ID_T);
--1.3: Define the primary key for the MV
ALTER MATERIALIZED VIEW MV_D_TIME ADD PRIMARY KEY (ID_T);
-----------------------------------------------------------------
--2: Define a materialized View for D_SALESMAN Dimension table
CREATE MATERIALIZED VIEW MV_D_SALESMAN
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
AS
SELECT
ROW_NUMBER() OVER (ORDER BY SALES_REP_ID) AS ID_S,--generate a unique ID for each row based on ID_S
SNAME
FROM T_SALESMAN;
--Display the content of the materialized view
SELECT * FROM MV_D_SALESMAN;
--2.1: Define the D_SALESMAN dimension using its created MV
CREATE TABLE D_SALESMAN AS
SELECT DISTINCT
ID_S,
SNAME
FROM MV_D_SALESMAN;
-- Add a primary key constraint to the D_SALESMAN table
ALTER TABLE D_SALESMAN
ADD CONSTRAINT PK_D_SALESMAN PRIMARY KEY (ID_S);
--2.3: Define the primary key for the MV
ALTER MATERIALIZED VIEW MV_D_SALESMAN ADD PRIMARY KEY (ID_S);
--------------------------------------------------------------
--3: Define a materialized View for D_CUSTOMERS Dimension table
CREATE MATERIALIZED VIEW MV_D_CUSTOMERS
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
AS
SELECT
ROW_NUMBER() OVER (ORDER BY ID_C) AS ID_C,--generate a unique ID for each row based on ID_C
CUSTOMER_ID,
CUST_FIRST_NAME AS C_FName,
CUST_LAST_NAME AS C_LName,
GENDER,
CUST_TYPE AS C_Type
FROM CUSTOMER_COPY;
-- Display the content of the materialized view
SELECT * FROM MV_D_CUSTOMERS;
-- Define the D_CUSTOMERS dimension using its created MV
CREATE TABLE D_CUSTOMERS AS
SELECT DISTINCT
ID_C,
C_FName,
C_LName,
GENDER,
C_Type
FROM MV_D_CUSTOMERS;
-- Add a primary key constraint to the D_CUSTOMERS table
ALTER TABLE D_CUSTOMERS
ADD CONSTRAINT PK_D_CUSTOMERS PRIMARY KEY (ID_C);
-----------------------------------------
-- Define a materialized View for D_ORDERS Dimension table
CREATE MATERIALIZED VIEW MV_D_ORDERS
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
AS
SELECT
ROW_NUMBER() OVER (ORDER BY ORDER_ID) AS ID_O,--generate a unique ID for each row based on ORDER_ID
ORDER_MODE AS OMode,
ORDER_STATUS AS Status
FROM ORDERS_COPY;
-- Display the content of the materialized view
SELECT * FROM MV_D_ORDERS;
-- Define the D_ORDERS dimension using its created MV
CREATE TABLE D_ORDERS AS
SELECT DISTINCT
ID_O,
OMode,
Status
FROM MV_D_ORDERS;
-- Add a primary key constraint to the D_ORDERS table
ALTER TABLE D_ORDERS
ADD CONSTRAINT PK_D_ORDERS PRIMARY KEY (ID_O);
--Q3 & 4 & 5: Creating the fact table F_ORDERS
--1: Create the fact table F_ORDERS
CREATE TABLE F_ORDERS (
F_ORDERS_ID INTEGER,
ORDER_AMOUNT DECIMAL(10,2),
ORDER_DATE DATE,
ID_C INTEGER,
ID_S INTEGER,
ID_T INTEGER,
ID_O INTEGER,
FOREIGN KEY (ID_C) REFERENCES D_CUSTOMERS (ID_C) ON DELETE CASCADE,
FOREIGN KEY (ID_S) REFERENCES D_SALESMAN (ID_S) ON DELETE CASCADE,
FOREIGN KEY (ID_O) REFERENCES D_ORDERS (ID_O) ON DELETE CASCADE,
FOREIGN KEY (ID_T) REFERENCES D_TIME (ID_T) ON DELETE CASCADE
);
--2: Define PK constraint for F_ORDERS_ID
ALTER TABLE F_ORDERS
ADD CONSTRAINT PK_F_ORDERS_ID PRIMARY KEY (F_ORDERS_ID);
--Q6: Create an Oracle Sequence starting with 1 for F_ORDERS_ID
CREATE SEQUENCE SEQ_F_ORDERS START WITH 1;SQL Worksheet
There is no
data?
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

Why should companies monitor their working capital?

Answered: 1 week ago

Question

3 4 6 .

Answered: 1 week ago

Question

1. How might volunteering help the employer and the employee?

Answered: 1 week ago