Skip to content

Commit

Permalink
Add indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
atrakic committed Dec 14, 2024
1 parent 385cab7 commit f294d01
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
23 changes: 16 additions & 7 deletions DbProject/dbo/Tables/DimCustomer.sql
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions DbProject/dbo/Tables/DimDate.sql
Original file line number Diff line number Diff line change
@@ -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
19 changes: 14 additions & 5 deletions DbProject/dbo/Tables/DimProduct.sql
Original file line number Diff line number Diff line change
@@ -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
13 changes: 9 additions & 4 deletions DbProject/dbo/Tables/FactSalesOrder.sql
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ 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:
- /bin/sh
- -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
Expand Down

0 comments on commit f294d01

Please sign in to comment.