AdventureWorksDW 数据库中的 DimTime 或 DimDate 表是否有任何免费下载替代品?我只想要这张桌子。此外,在未来 50 或 100 年会很棒。
谢谢,西姆
我不知道您对收到的回复是否满意,但您也可以根据您的业务需求创建自己的 DimDate 表。我基于 AdventureWorksDW212 DimDate 表结构编写了以下代码。
--change [YourDatabase] to your database's name
USE [YourDatabase]
GO
--First Create the Table (dbo.DimDate)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID('dbo.DimDate') IS NOT NULL
DROP TABLE dbo.DimDate;
CREATE TABLE [dbo].[DimDate](
[DateKey] [int] NOT NULL,
[FullDateAlternateKey] [date] NOT NULL,
[DayNumberOfWeek] [tinyint] NOT NULL,
[EnglishDayNameOfWeek] [nvarchar](10) NOT NULL,
[SpanishDayNameOfWeek] [nvarchar](10) NOT NULL,
[FrenchDayNameOfWeek] [nvarchar](10) NOT NULL,
[DayNumberOfMonth] [tinyint] NOT NULL,
[DayNumberOfYear] [smallint] NOT NULL,
[WeekNumberOfYear] [tinyint] NOT NULL,
[EnglishMonthName] [nvarchar](10) NOT NULL,
[SpanishMonthName] [nvarchar](10) NOT NULL,
[FrenchMonthName] [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,
CONSTRAINT [PK_DimDate_DateKey] PRIMARY KEY CLUSTERED
(
[DateKey] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY],
CONSTRAINT [AK_DimDate_FullDateAlternateKey] UNIQUE NONCLUSTERED
(
[FullDateAlternateKey] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
) ON [PRIMARY]
GO
--I have used the table structure to resemble the DimDate table
--in the AdventureWorksDW2012 DB but you can modify to meet your needs
--After the table is created, use the following code to populate the table:
--Create a DATE type variable (@StartDate) to hold the start date
DECLARE @StartDate AS DATE;
--Create another DATE Type variable (@EndDate) to hold the end date
DECLARE @EndDate AS DATE;
--Initialize @StartDate
SET @StartDate = '2015-01-01';
--Initialize @EndDate
SET @EndDate = '2020-12-31';
WHILE (@StartDate <= @EndDate)
BEGIN
--When populating the DimDate table,
--Use a set operation because it is much faster than the regular "INSERT INTO" operation!
INSERT dbo.DimDate
SELECT
CONVERT(char(8), @StartDate, 112) AS DateKey,
CONVERT(char(10), @StartDate, 126) AS FullDateAlternateKey,
DATEPART(DW, @StartDate) AS DayNumberOfWeek,
DATENAME(DW, @StartDate) AS EnglishDayNameOfWeek,
CASE
WHEN DATENAME(DW, @StartDate) = 'Saturday' THEN 'Sábado'
WHEN DATENAME(DW, @StartDate) = 'Sunday' THEN 'Domingo'
WHEN DATENAME(DW, @StartDate) = 'Monday' THEN 'Lunes'
WHEN DATENAME(DW, @StartDate) = 'Tuesday' THEN 'Martes'
WHEN DATENAME(DW, @StartDate) = 'Wednesday' THEN 'Miércoles'
WHEN DATENAME(DW, @StartDate) = 'Thursday' THEN 'Jueves'
WHEN DATENAME(DW, @StartDate) = 'Friday' THEN 'Viernes'
END AS SpanishDayNameOfWeek,
CASE
WHEN DATENAME(DW, @StartDate) = 'Saturday' THEN 'Samedi'
WHEN DATENAME(DW, @StartDate) = 'Sunday' THEN 'Dimanche'
WHEN DATENAME(DW, @StartDate) = 'Monday' THEN 'Lundi'
WHEN DATENAME(DW, @StartDate) = 'Tuesday' THEN 'Mardi'
WHEN DATENAME(DW, @StartDate) = 'Wednesday' THEN 'Mercredi'
WHEN DATENAME(DW, @StartDate) = 'Thursday' THEN 'Jeudi'
WHEN DATENAME(DW, @StartDate) = 'Friday' THEN 'Vendredi'
END AS FrenchDayNameOfWeek,
DATEPART(DD, @StartDate) AS DayNumberOfMonth,
DATEPART(dayofyear, @StartDate) AS DayNumberOfYear,
DATEPART(WK, @StartDate) AS WeekNumberOfYear,
DATENAME(MONTH, @StartDate) AS EnglishMonthName,
CASE
WHEN DATENAME(MONTH, @StartDate) = 'January' THEN'Enero'
WHEN DATENAME(MONTH, @StartDate) = 'February' THEN 'Febrero'
WHEN DATENAME(MONTH, @StartDate) = 'March' THEN 'Marzo'
WHEN DATENAME(MONTH, @StartDate) = 'April' THEN 'Abril'
WHEN DATENAME(MONTH, @StartDate) = 'May' THEN 'Mayo'
WHEN DATENAME(MONTH, @StartDate) = 'June' THEN 'Junio'
WHEN DATENAME(MONTH, @StartDate) = 'July' THEN 'Julio'
WHEN DATENAME(MONTH, @StartDate) = 'August' THEN 'Agosto'
WHEN DATENAME(MONTH, @StartDate) = 'September' THEN 'Septiembre'
WHEN DATENAME(MONTH, @StartDate) = 'October' THEN 'Octubre'
WHEN DATENAME(MONTH, @StartDate) = 'November' THEN 'Noviembre'
WHEN DATENAME(MONTH, @StartDate) = 'December' THEN 'Diciembre'
END AS SpanishMonthName,
CASE
WHEN DATENAME(MONTH, @StartDate) = 'January' THEN 'Janvier'
WHEN DATENAME(MONTH, @StartDate) = 'February' THEN 'Février'
WHEN DATENAME(MONTH, @StartDate) = 'March' THEN 'Mars'
WHEN DATENAME(MONTH, @StartDate) = 'April' THEN 'Avril'
WHEN DATENAME(MONTH, @StartDate) = 'May' THEN 'Mai'
WHEN DATENAME(MONTH, @StartDate) = 'June' THEN 'Juin'
WHEN DATENAME(MONTH, @StartDate) = 'July' THEN 'Juillet'
WHEN DATENAME(MONTH, @StartDate) = 'August' THEN 'Août'
WHEN DATENAME(MONTH, @StartDate) = 'September' THEN 'Septembre'
WHEN DATENAME(MONTH, @StartDate) = 'October' THEN 'Octobre'
WHEN DATENAME(MONTH, @StartDate) = 'November' THEN 'Novembre'
WHEN DATENAME(MONTH, @StartDate) = 'December' THEN 'Décembre'
END AS FrenchMonthName,
DATEPART(MONTH, @StartDate) AS MonthNumberOfyear,
DATEPART(Quarter, @StartDate) AS CalendarQuarter,
YEAR(@StartDate) AS CalendarYear,
CASE
WHEN DATEPART(MONTH, @StartDate) IN (1,2,3,4,5,6)
THEN 1
WHEN DATEPART(MONTH, @StartDate) IN (7,8,9,10,11,12)
THEN 2
END AS CalendarSemester,
CASE
WHEN DATEPART(MONTH, GetDATE()) IN (7, 8, 9) THEN 1
WHEN DATEPART(MONtH, GetDATE()) IN (10, 11, 12) THEN 2
WHEN DATEPART(MONtH, GetDATE()) IN (1, 2, 3) THEN 3
WHEN DATEPART(MONtH, GetDATE()) IN (4, 5, 6) THEN 4
END AS FiscalQuarter,
CASE
WHEN MONTH(@StartDate) < 7 THEN YEAR(@StartDate) --Assuming the fiscal year beings on the first of July
ELSE YEAR(@StartDate) + 1 --if the date is less than July, then the Fiscal Year is equal to the Calendar Year
END AS FiscalYear,
CASE
WHEN DATEPART(MONTH, @StartDate) IN (7,8,9,10,11,12) THEN 1
WHEN DATEPART(MONTH, @StartDate) IN (1,2,3,4,5,6) THEN 2
END AS FiscalSemester
--Increment the @StartDate by 1 here:
SET @StartDate = DATEADD(DAY, 1, @StartDate);
END
--You can now test your code by selecting from the table:
SELECT * FROM DimDate;
您可以使用 ETL 软件并自己生成这种表,例如在Pentaho ETL中应该是创建时间维度的示例转换。使用这种软件可以选择输出格式。使用这种软件可以选择输出格式。