Skip to content

Commit 01459d7

Browse files
committed
Add constrains
1 parent 218cb77 commit 01459d7

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

DbProject/dbo/Tables/DimCustomer.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE [dbo].[DimCustomer] (
2-
[CustomerKey] INT NOT NULL,
2+
[CustomerKey] INT NOT NULL PRIMARY KEY,
33
[CustomerAltKey] VARCHAR (50) NULL,
44
[Title] VARCHAR (5) NULL,
55
[FirstName] VARCHAR (50) NOT NULL,

DbProject/dbo/Tables/DimDate.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE [dbo].[DimDate] (
2-
[DateKey] INT NOT NULL,
2+
[DateKey] INT NOT NULL PRIMARY KEY,
33
[DateAltKey] DATE NOT NULL,
44
[DayOfWeek] INT NOT NULL,
55
[WeekDayName] VARCHAR (10) NULL,

DbProject/dbo/Tables/DimProduct.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE [dbo].[DimProduct] (
22
-- Update comment
3-
[ProductKey] INT NOT NULL,
3+
[ProductKey] INT NOT NULL PRIMARY KEY,
44
[ProductAltKey] VARCHAR (25) NULL,
55
[ProductName] VARCHAR (50) NOT NULL,
66
[Category] VARCHAR (50) NULL,
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
CREATE TABLE [dbo].[FactSalesOrder] (
2-
[SalesOrderKey] INT NOT NULL,
3-
[SalesOrderDateKey] INT NOT NULL,
4-
[ProductKey] INT NOT NULL,
5-
[CustomerKey] INT NOT NULL,
6-
[Quantity] INT NULL,
7-
[SalesTotal] DECIMAL (18) NULL
1+
CREATE TABLE [dbo].[FactSalesOrder]
2+
(
3+
[SalesOrderKey] INT NOT NULL,
4+
[SalesOrderDateKey] INT NOT NULL,
5+
[ProductKey] INT NOT NULL,
6+
[CustomerKey] INT NOT NULL,
7+
[Quantity] INT NULL,
8+
[SalesTotal] DECIMAL (18) NULL
9+
10+
CONSTRAINT [PK_FactSalesOrder] PRIMARY KEY CLUSTERED ([SalesOrderKey] ASC),
11+
CONSTRAINT [FK_FactSalesOrder_DimDate] FOREIGN KEY ([SalesOrderDateKey]) REFERENCES [dbo].[DimDate] ([DateKey]),
12+
CONSTRAINT [FK_FactSalesOrder_DimProduct] FOREIGN KEY ([ProductKey]) REFERENCES [dbo].[DimProduct] ([ProductKey]),
13+
CONSTRAINT [FK_FactSalesOrder_DimCustomer] FOREIGN KEY ([CustomerKey]) REFERENCES [dbo].[DimCustomer] ([CustomerKey])
814
);
915

1016
GO
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11

2-
3-
CREATE VIEW vSalesByRegion
4-
AS
5-
-- Deployment
6-
SELECT d.[Year] AS CalendarYear,
7-
d.[Month] AS MonthOfYear,
8-
d.MonthName AS MonthName,
9-
c.CountryRegion AS SalesRegion,
10-
SUM(so.SalesTotal) AS SalesRevenue
11-
FROM FactSalesOrder AS so
12-
JOIN DimDate AS d ON so.SalesOrderDateKey = d.DateKey
13-
JOIN DimCustomer AS c ON so.CustomerKey = c.CustomerKey
14-
GROUP BY d.[Year], d.[Month], d.MonthName, c.CountryRegion;
2+
CREATE VIEW vSalesByRegion
3+
AS
4+
SELECT d.[Year] AS CalendarYear,
5+
d.[Month] AS MonthOfYear,
6+
d.MonthName AS MonthName,
7+
c.CountryRegion AS SalesRegion,
8+
SUM(so.SalesTotal) AS SalesRevenue
9+
FROM
10+
FactSalesOrder AS so
11+
JOIN
12+
DimDate AS d ON so.SalesOrderDateKey = d.DateKey
13+
JOIN
14+
DimCustomer AS c ON so.CustomerKey = c.CustomerKey
15+
GROUP BY
16+
d.[Year], d.[Month], d.MonthName, c.CountryRegion;
1517

1618
GO

0 commit comments

Comments
 (0)