Created
December 16, 2019 21:06
-
-
Save codegard1/f3fe4320ea2c3c668469fc135964074e to your computer and use it in GitHub Desktop.
Sql script to create DimDate table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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