SQL Server Data Tools
新建Excel 源文件 C:\SSIS\Books_scd.xlsx ,内容如下。我们将创建一个表dbo.books_scd来接收数据库测试中的源数据。
在项目中打开包 SlowlyChangingDimension.dtsx,单击“Data Flow”选项卡,双击“Excel Connection Manager”打开设置窗口,并将 Excel file path设置为“C:\SSIS\Books_scd.xlsx”,然后单击“OK”按钮。
双击 Excel Source打开编辑器,然后单击“Columns”选项卡检查源数据列。
单击“OK”,然后双击Data Conversion任务打开编辑器,然后按如下所示进行设置。
单击“OK”,从 SSIS Toolbox拖放Slowly Changing Dimension控件到工作区域,并将输出数据连接到它。双击“Slowly Changing Dimension”任务打开“Slowly Changing Dimension Wizard”,然后单击“Next”按钮跳过欢迎页面。请在下面设置,然后单击“Next”,此时“Copy of Book Name”列的Key Type属性被设为“Business key”。
将“BoughtDate”的Change Type属性设置为“Changing attribute”,“Price” 的Change Type属性设置为“Historical attribute”和“Store” 的Change Type属性设置为“Fixed attribute”。
单击“Next”,取消选中“Fail the transformation if changes are detected in a fixed attribute”。
单击“Next”,将Historical Attribute Options设置如下。之所以显示此选项, 是因为在步骤6中我们将“Price”设置为“Historical attribute”。
单击“Next”,由于我们不会测试推断成员更新输出,取消选中“Enable inferred member support”。
单击 “Next”,然后单击“Finish”按钮,就新建了New Output、Historical Attribute Inserts Output和Changing Attribute Updates Output。
拖放将2 个Row Count控件到工作区域,并为其创建和分配2个Int32变量。将Slowly Changing Dimension 任务的Fixed Attribute Output和Unchanged Output输出连接到2个Row Count任务上,然后在所有输出上启用数据查看器。
运行包,您将看到4记录全部进入New Output,因为表中没有任何记录。然后再次运行包,可以看到4条记录输出到Unchanged Output。
如下修改源数据,红色方块表示已更改的数据。
再次运行包。由于Store列中的数据已改变,Book D 的数据流入Fixed Attribute Output。由于Price列中的数据已改变,Book A, C的数据流入Historical Attribute Output。由于BoughtDate 列中的数据已改变,Book B的数据流入Changing Attribute Updates Output。Fixed Attribute Output具有输出数据的最高优先级,然后是Historical Attribute Output,最后是Changing Attribute Updates Output。
检查数据库中的数据。显然,记录1和3是过期记录,并设置了过期日期。通过使用表中的“Flag”字段,我将让读者将步骤11改为“Use a single column to show current and expired records”,下面的 SQL 语句可用于删除表 books_scd 中的所有记录以便重新开始运行包。TRUNCATE TABLE dbo.books_scd