Skip to content

Instantly share code, notes, and snippets.

@codegard1
Created December 16, 2019 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegard1/f3fe4320ea2c3c668469fc135964074e to your computer and use it in GitHub Desktop.
Save codegard1/f3fe4320ea2c3c668469fc135964074e to your computer and use it in GitHub Desktop.
Sql script to create DimDate table
USE AWDataWarehouse
GO
-- Create DimDate dimension table
CREATE TABLE [dbo].[DimDate](
[DateKey] [int] NOT NULL PRIMARY KEY NONCLUSTERED,
[FullDateAlternateKey] [date] NOT NULL,
[DayNumberOfWeek] [tinyint] NOT NULL,
[DayNameOfWeek] [nvarchar](10) NOT NULL,
[DayNumberOfMonth] [tinyint] NOT NULL,
[DayNumberOfYear] [smallint] NOT NULL,
[WeekNumberOfYear] [tinyint] NOT NULL,
[MonthName] [nvarchar](10) NOT NULL,
[MonthNumberOfYear] [tinyint] NOT NULL,
[CalendarQuarter] [tinyint] NOT NULL,
[CalendarYear] [smallint] NOT NULL,
[CalendarSemester] [tinyint] NOT NULL,
[FiscalQuarter] [tinyint] NOT NULL,
[FiscalYear] [smallint] NOT NULL,
[FiscalSemester] [tinyint] NOT NULL
)
GO
-- Create relationships to DimDate
ALTER TABLE [dbo].FactInternetSales
ADD
OrderDateKey int NULL REFERENCES [dbo].DimDate(DateKey),
ShipDateKey int NULL REFERENCES [dbo].DimDate(DateKey)
GO
ALTER TABLE [dbo].FactResellerSales
ADD
OrderDateKey int NULL REFERENCES [dbo].DimDate(DateKey),
ShipDateKey int NULL REFERENCES [dbo].DimDate(DateKey)
GO
-- Create indexes on date key fields
CREATE NONCLUSTERED INDEX [IX_FactInternetSales_OrderDateKey] ON [dbo].FactInternetSales
(
[OrderDateKey] ASC
)
GO
CREATE NONCLUSTERED INDEX [IX_FactInternetSales_ShipDateKey] ON [dbo].FactInternetSales
(
[ShipDateKey] ASC
)
GO
-- Create indexes on date key fields
CREATE NONCLUSTERED INDEX [IX_FactResellerSales_OrderDateKey] ON [dbo].FactResellerSales
(
[OrderDateKey] ASC
)
GO
CREATE NONCLUSTERED INDEX [IX_FactResellerSales_ShipDateKey] ON [dbo].FactResellerSales
(
[ShipDateKey] ASC
)
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment