diff --git a/DbProject/dbo/Tables/DimCustomer.sql b/DbProject/dbo/Tables/DimCustomer.sql index fc7bbe3..26f5f81 100644 --- a/DbProject/dbo/Tables/DimCustomer.sql +++ b/DbProject/dbo/Tables/DimCustomer.sql @@ -1,11 +1,20 @@ -CREATE TABLE [dbo].[DimCustomer] ( - [CustomerKey] INT NOT NULL PRIMARY KEY, - [FirstName] VARCHAR (50) NOT NULL, - [LastName] VARCHAR (50) NULL, - [AddressLine1] VARCHAR (200) NULL, - [City] VARCHAR (50) NULL, - [PostalCode] VARCHAR (20) NULL +CREATE TABLE [dbo].[DimCustomer] +( + [CustomerKey] INT IDENTITY(1,1) NOT NULL PRIMARY KEY, + [FirstName] VARCHAR (50) NOT NULL, + [LastName] VARCHAR (50) NOT NULL, + [AddressLine1] VARCHAR (200) NOT NULL, + [City] VARCHAR (50) NOT NULL, + [PostalCode] VARCHAR (20) NOT NULL, + [SurrogateKey] INT NOT NULL ); +GO +CREATE INDEX IX_DimCustomer_Name ON [dbo].[DimCustomer] ([FirstName], [LastName]); +GO +CREATE INDEX IX_DimCustomer_Address ON [dbo].[DimCustomer] ([AddressLine1], [City], [PostalCode]); +GO +ALTER TABLE [dbo].[DimCustomer] +ADD CONSTRAINT AK_DimCustomer UNIQUE ([FirstName], [LastName], [AddressLine1], [City], [PostalCode]); GO diff --git a/DbProject/dbo/Tables/DimDate.sql b/DbProject/dbo/Tables/DimDate.sql index e877efa..77af68d 100644 --- a/DbProject/dbo/Tables/DimDate.sql +++ b/DbProject/dbo/Tables/DimDate.sql @@ -1,7 +1,9 @@ -CREATE TABLE [dbo].[DimDate] ( - [DateKey] INT NOT NULL PRIMARY KEY, - [Date] DATE NOT NULL +CREATE TABLE [dbo].[DimDate] +( + [DateKey] INT NOT NULL PRIMARY KEY, + [Date] DATE NOT NULL ); +GO - +CREATE INDEX IX_DimDate_DateKey ON [dbo].[DimDate] ([DateKey]); GO diff --git a/DbProject/dbo/Tables/DimProduct.sql b/DbProject/dbo/Tables/DimProduct.sql index a190420..654bea6 100644 --- a/DbProject/dbo/Tables/DimProduct.sql +++ b/DbProject/dbo/Tables/DimProduct.sql @@ -1,9 +1,18 @@ -CREATE TABLE [dbo].[DimProduct] ( - [ProductKey] INT NOT NULL PRIMARY KEY, - [ProductName] VARCHAR (50) NOT NULL, - [Category] VARCHAR (50) NULL, - [ListPrice] DECIMAL (18) NULL +CREATE TABLE [dbo].[DimProduct] +( + [ProductKey] INT IDENTITY(1,1) NOT NULL PRIMARY KEY, + [ProductName] VARCHAR (50) NOT NULL, + [Category] VARCHAR (50) NOT NULL, + [ListPrice] DECIMAL (18, 2) NOT NULL ); +GO + +CREATE INDEX IX_DimProduct_Name ON [dbo].[DimProduct] ([ProductName]); +GO +CREATE INDEX IX_DimProduct_Category ON [dbo].[DimProduct] ([Category]); +GO +ALTER TABLE [dbo].[DimProduct] +ADD CONSTRAINT AK_DimProduct UNIQUE ([ProductName], [Category]); GO diff --git a/DbProject/dbo/Tables/FactSalesOrder.sql b/DbProject/dbo/Tables/FactSalesOrder.sql index 39d6bad..58fff99 100644 --- a/DbProject/dbo/Tables/FactSalesOrder.sql +++ b/DbProject/dbo/Tables/FactSalesOrder.sql @@ -1,16 +1,21 @@ CREATE TABLE [dbo].[FactSalesOrder] ( - [SalesOrderKey] INT NOT NULL, + [SalesOrderKey] INT IDENTITY(1,1) NOT NULL PRIMARY KEY, [SalesOrderDateKey] INT NOT NULL, [ProductKey] INT NOT NULL, [CustomerKey] INT NOT NULL, - [Quantity] INT NULL, - [SalesTotal] DECIMAL (18) NULL + [Quantity] INT NOT NULL DEFAULT 0, + [SalesTotal] DECIMAL (18, 2) NOT NULL DEFAULT 0.00, - CONSTRAINT [PK_FactSalesOrder] PRIMARY KEY CLUSTERED ([SalesOrderKey] ASC), CONSTRAINT [FK_FactSalesOrder_DimDate] FOREIGN KEY ([SalesOrderDateKey]) REFERENCES [dbo].[DimDate] ([DateKey]), CONSTRAINT [FK_FactSalesOrder_DimProduct] FOREIGN KEY ([ProductKey]) REFERENCES [dbo].[DimProduct] ([ProductKey]), CONSTRAINT [FK_FactSalesOrder_DimCustomer] FOREIGN KEY ([CustomerKey]) REFERENCES [dbo].[DimCustomer] ([CustomerKey]) ); +GO +CREATE INDEX IX_FactSalesOrder_DateKey ON [dbo].[FactSalesOrder] ([SalesOrderDateKey]); +GO +CREATE INDEX IX_FactSalesOrder_ProductKey ON [dbo].[FactSalesOrder] ([ProductKey]); +GO +CREATE INDEX IX_FactSalesOrder_CustomerKey ON [dbo].[FactSalesOrder] ([CustomerKey]); GO diff --git a/compose.yml b/compose.yml index 92f90e1..fbe6b7e 100644 --- a/compose.yml +++ b/compose.yml @@ -9,6 +9,8 @@ services: - .env environment: ConnectionString: "Server=tcp:db,1433;Initial Catalog=demo;UID=sa;Password=${MSSQL_SA_PASSWORD};TrustServerCertificate=true;Connection Timeout=3;" + # keep the container alive for debugging + DEBUG: "${DEBUG:-}" volumes: - $PWD/SQL/dw-seed.sql:/seed.sql entrypoint: @@ -16,8 +18,7 @@ services: - -c - | ./SqlClient.ConsoleApp /seed.sql - # keep the container running (for debugging) - #tail -f /dev/null + if [ -n "$DEBUG" ];then tail -f /dev/null; fi depends_on: sqlpackage: condition: service_completed_successfully