我正在尝试使用数据流任务将数据加载到我的 DimEmployee 表中。但是,我注意到当我运行 SSIS 时,DimEmployee 填充了 9 条记录中的 4 条,而且 EmpKey 从 -1 开始计数,然后生成随机数!运行包时我也有一个相关的警告:
警告 1 验证警告。数据流任务:{DC10B0CA-A6DE-4036-98A6-496811C09D4A}:由于将数据从长度为 25 的数据流列“TitleOfCourtesy”插入到长度为 8 的数据库列“Title”,可能会发生截断。DimEmployee.dtsx 0 0
我在我的 SSMS 中创建了一个过程,它应该用“未知”来填充列中的空值
USE [NorthWindDW]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Insert_New_Employee]
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS
(
SELECT * FROM [dbo].DimEmployee
WHERE EmpKey = -1
)
BEGIN
SET IDENTITY_INSERT [dbo].[DimEmployee] ON
INSERT [dbo].[DimEmployee] (EmpKey, EmpId,Title, EmpFirstName, EmpLastName, HireDate,Country, StoreCode, Telephone,JobTitle) VALUES
(-1,-1,'UNKNOWN','UNKNOWN','UNKNOWN','1900-01-01', 'UNKNOWN','UNKNOWN', 'UNKNOWN','UNKNOWN');
SET IDENTITY_INSERT [dbo].[DimEmployee] OFF
END
END
GO
这是我的 DimEmployee 表
Create Table [dbo].[DimEmployee]
(EmpKey INT IDENTITY NOT NULL,
EmpId INT NOT NULL,
EmpFirstName NVARCHAR(50) NOT NULL,
EmpLastName NVARCHAR(50) NOT NULL,
Title NVARCHAR(8) NOT NULL,
HireDate DATE NOT NULL,
Country NVARCHAR(50) NOT NULL,
StoreCity NVARCHAR(50) NOT NULL,
Telephone NVARCHAR(25) NOT NULL,
JobTitle NVARCHAR(50) NOT NULL);
Go