0% found this document useful (0 votes)
43 views3 pages

Laboratory Exercises #2

1. The document provides instructions for a laboratory exercise to design a star schema in SQL Server. 2. Students are asked to create four tables to represent facts and dimensions, then load CSV files into these tables using an SSIS package. 3. A view is to be created joining the tables to generate sales reports, and four types of reports summarizing sales quantity and amount by date, week, customer and date, and customer and week are to be developed.

Uploaded by

Lewis Punzalan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Laboratory Exercises #2

1. The document provides instructions for a laboratory exercise to design a star schema in SQL Server. 2. Students are asked to create four tables to represent facts and dimensions, then load CSV files into these tables using an SSIS package. 3. A view is to be created joining the tables to generate sales reports, and four types of reports summarizing sales quantity and amount by date, week, customer and date, and customer and week are to be developed.

Uploaded by

Lewis Punzalan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Laboratory Exercises # 2

Designing Star Schema (Datawarehouse)

1. Open SQL Server Management Studio and create database name DW. (Please refer to your
previous laboratory exercises on how to create database TestDB)

Then in your newly created DW database, paste the script below and click <Execute> to create 4 new
tables (DimCalendar, DimCustomer, DimProducts and FactSales)

CREATE TABLE [dbo].[DimCalendar](


[CalendarDate] [datetime] NULL,
[CalendarDay] [varchar](50) NULL,
[Holiday] [varchar](50) NULL,
[WeekNumber] [int] NULL
) ;

CREATE TABLE [dbo].[DimCustomer](


[CustomerID] [int] NULL,
[CustomerName] [varchar](50) NULL
);

CREATE TABLE [dbo].[DimProducts](


[ProductNo] [int] NULL,
[ProductName] [varchar](255) NULL,
[ProducType] [varchar](50) NULL,
[Category] [varchar](50) NULL,
[Price] [float] NULL,
[EffectiveStartDate] [datetime] NULL,
[EffectiveEndDate] [datetime] NULL
) ;

CREATE TABLE [dbo].[FactSales](


[DateSold] [datetime] NULL,
[ProductNo] [int] NULL,
[CustomerID] [int] NULL,
[Qty] [int] NULL
) ;
2. Then create an SSIS package to import the following CSV files to the 4 tables you just created in
step 1.

3. Then Create an SQL View named (vw_FactSalesSummary) to join the 4 tables DimCalendar,
DimCustomer, DimProducts and FactSales with the following columns included.

 (FactSales) - DateSold, ProductNo, CustomerID, Qty


 (DimCalendar) - CalendarDay, Holiday, WeekNumber
 (DimProducts) - ProductName, ProducType, Category, Price*
 (DimCustomer) – CustomerName
 TotalAmountSold**

*Give a new column name PricePerUnit


** TotalAmountSold= Qty x Price

You should now see your newly created vw_FactSalesSummary in DW database

4. Using the view vw_FactSalesSummary, create a query that will generate the following reports

 Sales Summary (Quantity, AmountSold) per day


 Sales Summary (Quantity, AmountSold) per week
 Sales Summary (Quantity, AmountSold) per customer, per day
 Sales Summary (Quantity, AmountSold) per customer, per week
Reminder:

1. Send the query of the view and the 4-Sales summary report on a separate doc or note (not
screenshot).

2. Send the screenshot of the result query (views and the 4 Sales summary reports)

3. Submission is on December 19, 2022 EOD

4. For those who doesn’t have PC/Laptop, create a step-by-step process on how are you going to
generate the view and the 4 Sales Summary reports (same to what you did last lab exercises). Using the
4 CSV files as a reference, please generate the report and place it on excel or any docs that you can
display the reports in table like below.

Reference:

Sample View query


ALTER VIEW vw_FactSales_Summary
AS

SELECT c.CalendarDay,c.WeekNumber
,fs.*
,p.ProductName, p.Price AS 'PricePerUnit'
,(fs.Qty * p.Price ) AS TotalAmountSold
FROM [dbo].[FactSales] fs
JOIN [dbo].[DimCalendar] c ON fs.DateSold=c.CalendarDate
JOIN [dbo].[DimProducts] p ON p.ProductNo=fs.ProductNo
AND fs.DateSold BETWEEN P.EffectiveStartDate AND
ISNULL(p.EffectiveEndDate,GETDATE())

Sample Sales per week query


SELECT f.WeekNumber
, SUM(f.Qty) AS TotalQty
,SUM(f.TotalAmountSold) AS TotalAmtSold
FROM [dbo].[vw_FactSales_Summary] f
GROUP BY f.WeekNumber

You might also like