Hands-On Lab: Building Your First Extract-Transform-Load Process With SQL Server 2008 R2 Integration Services
Hands-On Lab: Building Your First Extract-Transform-Load Process With SQL Server 2008 R2 Integration Services
OVERVIEW................................................................................................................................................. 3
SUMMARY................................................................................................................................................ 21
Overview
This lab introduces Integration Services package design specifically to populate a fact table.
Note: Before you start with this exercise you must ensure that your machine meets the system
requirements detailed in the next section. Additionally, you must complete the setup steps described
in the next section.
Objectives
The objectives of this exercise are to:
Create an Integration Services project
Define package variables
Define package connection managers
Configure control flow
Configure data flow
System Requirements
You must have installed the following items to complete this lab:
Microsoft SQL Server 2008 R2:
◦ Database Engine
◦ Integration Services
◦ SQL Server Business Intelligence Development Studio
◦ SQL Server Management Studio
SQL Server AdventureWorks2008 R2 sample databases
◦ AdventureWorks Data Warehouse 2008R2
Setup
All the requisites for this lab are verified using the Configuration Wizard. To make sure that everything is
correctly configured, follow these steps.
Note: To perform the setup steps you need to run the scripts in a command window with
administrator privileges.
1. Launch the Configuration Wizard for this lab by double-clicking the Dependencies.dep file
located under the Source\Setup folder of this lab. Install any pre-requisites that are missing
(rescanning if necessary) and complete the wizard.
Cleanup
There is no need to cleanup if you intend to continue the sequence of labs in this training kit.
1. To restore the original state of the AdventureWorksDW2008R2 database, execute the
Cleanup.cmd script located under the Setup folder in the Source folder of this lab.
Exercises
This Hands-On Lab comprises the following exercise:
1. Populating the FactSalesQuota Table
Property Value
Server Name SqlServerTrainingKitAlias
Authentication Windows Authentication
Figure 1
Selecting the AdventureWorksDW2008R2 Database
Figure 2
Selecting the Visual Studio Solutions Project Type
4. In the Templates pane, ensure Blank Solution is selected, then in the Name box, replace the
text with AdventureWorksBI.
5. To set the project location, click Browse.
6. In the Project Location window, navigate to the Source folder for this lab, and then click
Select Folder.
7. In the New Project window, click OK.
8. When the solution is created, in Solution Explorer, right-click the AdventureWorksBI
solution, and then select Add | New Project.
9. In the Add New Project window, in the Templates pane, select Integration Services Project.
10. In the Name box, replace the text with Populate DW, and then click OK.
Note: The Populate DW Integration Services project is added to the solution and a default
package, Package.dtsx, is added to the project. The package is automatically opened in the
package designer.
11. To rename the package, in Solution Explorer, right-click Package.dtsx, and then select
Rename.
12. Modify the name to LoadFactSalesQuota.dtsx, and then press Enter.
13. When prompted to rename the package object, click Yes.
14. To save the solution, on the File menu, select Save All.
Figure 4
Configuring the Data Flow Auto Connect
8. Click OK.
Figure 5
Add a New Variable
3. Modify the name of the variable to Year, and then scroll to the right to modify the Value to
2008.
Note: This variable will be used to dynamically configure the package behavior. When
executing the package it is be possible to update the variable’s value in order to load data for
any given year.
Note: This variable will be used to store the folder path where the quota extracts are stored.
11. Verify that the two package variables look like the following.
Figure 6
Verifying the Package Variables
Figure 7
Selecting the Columns Page
Note: The editor has parsed the data in the opened file and has automatically determined the
row and column delimiters.
Note: If the Properties window is not open, on the View menu, select Properties Window.
16. In the Property Expressions Editor window, in the Property column, select
ConnectionString, and then at the end of the row, click the ellipsis button top open the
Expression Builder.
Figure 8
Configuring the ConnectionString Expression
17. In the Expression Builder window, expand the Variables folder, and then drag the
User::FolderPath variable into the Expression box.
18. Complete the expression based on the following.
Note: The expression required in this step may be copied from the Assets\Snippets.txt file in
the Source folder of this lab.
Note: Inside a string literal Integration Services interprets the backslash (\) as an escape
character. To produce a backslash in the string literal two backslashes are required. Note also
the cast operator that converts the Year variable value (integer) to a four character Unicode
string.
19. Click Evaluate Expression to review the file path for the 2008 quota extract file, and then
click OK.
20. In the Property Expressions Editor window, click OK.
Property Value
Server Name SqlServerTrainingKitAlias
Database Name AdventureWorksDW2008R2
Note: If the Toolbox is not open, on the View menu, select Toolbox.
The Toolbox is used frequently during package development. It is recommended that you click
the pushpin to keep the Toolbox permanently open.
2. To rename the Sequence Container , right-click the container, and then select Rename.
3. Modify the text to Update FactSalesQuota, and then press Enter.
4. To configure the transaction support, ensure the container is selected, and then in the
Properties window, modify the TransactionOption property to Required.
Property Value
Name Delete Existing Quotas
Connection AdventureWorksDW2008R2
SQLStatement EXEC dbo.uspDeleteFactSalesQuota ?
Note: The stored procedure in the SQLStatement property requires a single input parameter
named @CalendarYear. The question mark (?) is a placeholder for this parameter.
4. Double-click the Delete Existing Quotas task to reopen the Execute SQL Task Editor window
and select the ParameterMapping page.
5. To add a parameter mapping, click Add.
6. In the Variable Name column, select User::Year.
7. In the Parameter Name column, replace the text with @CalendarYear, and then click OK.
Task 10 – Introducing the Data Flow Task
In this task, you will add a Data Flow Task and then create a precedence constraint that ensures this task
execute upon successful completion of the Execute SQL Task.
1. From the Toolbox, drag the Data Flow Task and drop it inside the Update FactSalesQuota
container, directly beneath the Delete Existing Quotas task.
2. To rename the Data Flow Task, right-click it, and then select Rename.
3. Modify the text to Insert New Quotas, and then press Enter.
4. To introduce a precedence constraint, select the Delete Existing Quotas task, and then drag
the green arrow connector onto the Insert New Quotas task.
5. Review that your package control flow resembles the following.
Figure 9
Reviewing the Package Control Flow
Note: The package designer switches to the Data Flow tab. In this tab you will assemble the
data flow. Notice also that the content of the Toolbox now consists of the data flow
components, categorized by sources, transformations and destinations.
Task 12 – Introducing the Flat File Source
In this task, you will add a Flat File Source and configure it to retrieve the data from the Sales Quota
connection manager.
1. From the Toolbox, from inside the Data Flow Sources category, drag the Flat File Source and
drop it into the package designer.
2. To rename the component, right-click the Flat File Source, and then select Rename.
3. Modify the text to Sales Quota, and then press Enter.
4. To configure the component, right-click it, and then select Edit.
5. In the Flat File Source Editor window, in the Flat File Connection Manager dropdown list,
ensure the Sales Quota connection manager is selected.
6. To review the data in the file, click Preview.
7. In the Data View window, click Close.
8. Select the Columns page.
9. Review the columns to be output by this component, and then click OK.
Note: The introduction, layout alignment and auto connection of the component happened
because you configure the Integration Services designer options in Task 4.
Note: The output of this component will have three columns: EmployeeID, CalendarQuarter,
and SalesAmountQuota. The CalendarQuarter column will contain the Pivot Key Value of 1, 2,
3 or 4. A downstream component that you will configure shortly will convert these numbers to
the first day of the first month of the quarter. The SalesAmountQuota column will contain the
value that was previously stored in the quota extract file at the intersection of the EmployeeID
and the quarter.
4. Right-click the Unpivot component, and then select Show Advanced Editor.
5. In the Advanced Editor for Unpivot window, select the Input and Output Properties tab.
6. In the Inputs And Outputs pane, expand Unpivot Output, and then expand Output Columns.
7. Select the CalendarQuarter column, modify the DataType property to Single-Byte Unsigned
Integer [DT_UI1], and then click OK.
Note: The expressions required in the following steps may be copied from the
Assets\Snippets.txt file in the Source folder of this lab.
1. Select the Unpivot component, then in the Toolbox, from inside the Data Flow
Transformations category, double-click the Derived Column component.
2. Right-click the Derived Column component, and then select Edit.
3. In the Derived Column Transformation Editor window, in the Derived Column Name
column, type DateKey.
4. In the Expression column, type the following expression.
SSIS Expression Language
(@[User::Year] * 10000) + ((([CalendarQuarter] * 3) - 2) * 100) + 1
Figure 11
Reviewing the Derived Column Definitions
Note: The query required in the following steps may be copied from the Assets\Snippets.txt
file in the Source folder of this lab.
T-SQL
SELECT EmployeeKey, EmployeeNationalIDAlternateKey
FROM dbo.DimEmployee
WHERE (SalesPersonFlag=1) AND (CurrentFlag=1);
Figure 12
Configuring the Lookup Column
Note: When you select this page for the first time, column mappings are automatically
assigned when the column names match and the data types of the matched columns are at
least equivalent. Because all insertable columns have been mapped by this step, you do not
need to perform any additional mapping configurations. Note that the SalesQuotaKey column
is an identity column; SQL Server will automatically insert unique sequential values into this
column.
9. Click OK.
10. Review that your data flow resembles the following.
Figure 13
Reviewing the Data Flow
Figure 14
Selecting the Variables Window
6. In the Variables window, modify the value of the Year variable to 2009.
7. Repeat the steps in this task to execute the package again.
Task 19 – Finishing Up
In this task, you will finish up by closing all applications.
1. In SQL Server Management Studio, on the File menu, select Exit.
2. When prompted to save changed, click No.
3. In SQL Server Business Intelligence Development Studio, on the File menu, select Exit.
Summary
In this lab, you have created an Integration Services package to populate the data warehouse’s
FactSalesQuota table.