Creating SSIS Packages: SQL Server 2005
Creating SSIS Packages: SQL Server 2005
2008
1
SQL SERVER 2005
Table of Contents
ii
SQL SERVER 2005
7. Double click the icon in the task you just created to open the Properties
box. Under General, set the Name to DELETE Entity Records. Under SQL
Statement, Connection, choose MSRBDMS, and for SQL Statement, enter
DELETE from Entity.
8. Repeat steps 7 and 8 for an Execute SQL task named DELETE Address Records
from MSRBDMS and enter the SQL Statement DELETE from Address.
9. Drag the green arrow form the DELETE Entity Records onto the DELETE
Address Records to connect them in the data flow.
10. Repeat steps 7 and 8 for an Execute SQL task named DELETE Communication
Records from MSRBDMS and enter a SQL Statement DELETE from
Communication.
11. Drag the green arrow form the DELETE Address Records onto the DELETE
Communication Records to connect them in the data flow.
12. Save your work.
EXHIBIT 2.
Data Flow Task for Entity.
2
4. Double-click the icon to open the OLE DB Source Editor box and set the
OLE DB connection manager to your source MS_RBDMS and set the name of
the table to [dbo].[tblRefCompany].
5. Still in the OLE DB Source Editor, under Columns, uncheck everything except
CoNo, Stat, and CoName. Click OK.
6. Next, create a data conversion task by dragging one from the toolbox to the
workspace. Drag the green arrow from tblRefCodes onto the Data Conversion
task to connect them in the flow.
9. Double click the icon to open the Derived Column Transformation Editor.
In the field under Derived Column Name, enter EntityType. Under Expression
for EntityType, enter “CO” and set the data type to string [DT_STR]. Click OK.
10. Next, create the Entity Destination. From the toolbox, drag an OLE DB
Destination to the workspace beneath the Derived Column task and rename it
Entity Destination. Drag the green arrow from the Derived Column task onto
the Entity Destination to connect then in the data flow.
11. Double-click the icon to open the OLE DB Destination Editor. In the OLE
DB Connection Manager, select your destination source MSRBDMS. In the
Name of the table, select [dbo].[Entity].
12. In Mappings in the OLE DB Destination Editor, match the input and destination
columns using the dropdown boxes as follows:
a. Copy of CoName to EntityName
b. Copy of Stat to Status
c. EntityType to EntityType
d. CoNo to CoNo
13. Save your work.
3
Develop the Address Data Flow
Next, we’ll create another data flow task for Address. The SSIS data flows also show the
importance of staging the data import to begin with data from the core RBDMS tables.
When the exercise is complete, the data flow will look similar to the image shown in
Exhibit 3. Note how the
translation and importation of
address data is tied to the
results of the previous SSIS
package runs:
1. Return to the Control
Flow (see Exhibit 1 to re-
gain your bearings).
2. From the toolbox, drag a
Data Flow Task onto the
workspace below Entity
and rename it Address
Data. Drag the green
arrow from the Entity
data flow task onto the
Address data flow task
so that they are
connected.
3. Double-click the
5. Double-click the icon to open the OLE DB Source Editor. The OLE DB
connection manager should be set to your source database MS_RBDMS. For the
Data access mode, select SQL command and either build or copy and paste the
following SELECT statement and click OK:
SELECT CoNo, Addr1, Addr2, City, State, Zip1 + '-'
+ ISNULL(Zip2, '') AS Expr1, Country
FROM tblRefCompany
4
6. Check the Columns to make sure the external column and the output column are
aligned and click OK.
7. Add a Data Conversion task to the workspace below the tblRefCompanyAddress
OLE DB Source. Drag the green arrow from tblRefCompanyAddress to the Data
Conversion task so that they are connected.
10. Double-click the icon to open the Sort Transformation Editor. Select the CoNo
column for sorting and click OK.
11. Drag an OLE DB Source from the toolbox onto the workspace next to the one for
tblRefCompany Address and rename it Entity.
12. Double-click the icon to open the OLE DB Source Editor. Set the OLE DB
connection manager to your destination database MSRBDMS. For the Data
access mode, leave the default selection of Table or view. For the name of the
table, select [dbo].[Entity].
13. In the OLE DB Source Editor, click Columns and uncheck everything in the
Available External Columns list except for PKey and CoNo. Click OK.
14. Next add a Sort data flow transformation task below the Entity Data Conversion
task and link them by dragging the green arrow from Data Conversion to Sort.
15. Double-click the icon to open the Sort Transformation Editor. Select the CoNo
column for sorting and click OK.
16. From the toolbar, drag a Merge Join data transformation task onto the
workspace. Drag the green arrow from the Sort task below
tblRefCompanyAddress onto the Merge Join. When prompted to edit the Input
Output Selection, for Input, select Merge Join Left Input. Repeat for the Sort task
beneath Entity as Merge Join Right Input.
17. Double-click the icon in the Merge Join task to open the Merge Join
Transformation Editor. In the top pane for the left sort add the following inputs
5
by checking all of the fields except for CoNo. For the right Sort task, check only
the PKey.
18. In the lower pane, locate the Input Column for the PKey and change its Output
Alias to EntityPkey. Click OK.
19. End by dragging an OLE DB Destination task from the toolbar to the bottom
center of the workspace. Rename the task Address Destination. Connect the
Merge Join task to the Address Destination by dragging the green arrow from
Merge Join onto Address Destination.
20. Double-click the icon to open the OLE DB Destination Editor. In the OLE
DB Connection Manager, select your destination source MSRBDMS. Leave the
data access mode set as Table or view, and for the Name of the table, select
[dbo].[Address].
21. In the OLE DB Destination Editor, click Mappings and then match the input and
destination columns using the dropdown boxes as follows and then click OK.
a. <ignore> to PKey
b. Entity Pkey to Entity Key
c. Copy of Addr1 to Address1
d. Copy of Addr2 to Address2
e. Copy of City to City
f. Copy of State to State
g. Copy of Expr1 to PostalCode
h. Copy of Country to Country
i. <ignore> to TempID
22. Save your work.
6
Develop the EntityType Data Flow
The EntityType data flow is the most involved component of the ImportEntity.dtsx
package merely because of the repetition required to develop it. The left side sort in the
diagram splits out the various entity types, while the right side sort assigns the keys in
the resulting import operation. Since the individual steps are as straightforward as the
others demonstrated in this exercise, the class session will track only one of the fourteen
paths, which will be typical for the thirteen the others. The participants are welcome to
carry on the pattern independently. The completed data flow will look like Exhibit 4 in
the BIDS workspace.
EXHIBIT 4.
The EntityType Data Flow.
7
1. Return to the Summary Control Flow. Add a data flow task from the toolbox to
the workspace beneath Address Data. Rename the new data flow task
EntityType. Connect Address Data to EntityType by dragging the green arrow
from Address Data onto EntityType.
2. Double-click the icon on the EntityType data flow task to enter the
workspace to begin defining the steps in the flow.
3. Drag an OLE DB Source from the toolbox onto the workspace and rename it
Entity Types Source.
4. Double-click the icon to open the OLE DB Source Editor. The OLE DB
connection manager should be set to your source database MS_RBDMS. For the
Data access mode, select SQL command and either build or copy and paste the
following SELECT statement:
SELECT Oper, Inj_Oper, Driller, Bond_Co,
Logg_Contr, Cement_Contr, Watr_Haul, Service, Docket,
Misc2, NaturalGasOperator, Oil_Trans, Gas_Gathr,
Oil_Purchr, Gas_Purchr,
Plugging, Bulk_, OilCompany, CoNo
FROM dbo.tblRefCompany
5. Check the Columns to make sure the external column and the output column are
aligned and click OK.
6. Double-click the icon to open the Sort Transformation Editor. Select the CoNo
column for sorting and click OK.
7. Drag another OLE DB Source from the toolbox onto the workspace to the right of
the Entity Types Source and rename the new OLE DB Source Entity.
8. Double-click the icon to open the OLE DB Source Editor. The OLE DB
connection manager should be set to your destination database MSRBDMS.
Leave the Data access mode set to Table or view, and for the Name of the table
or view, select [dbo].[Entity].
9. In the OLE DB connection manager, click Columns. For the Available External
Columns list, uncheck all of the named columns except for PKey and CoNo. Then
click OK.
8
10. Next add another Sort transformation task below Entity and link them by
dragging the green arrow from Entity to Sort.
11. Double-click the icon to open the Sort Transformation Editor. Select the CoNo
column for sorting and click OK.
12. From the toolbar, drag a Merge Join data transformation task onto the workspace
between the two Sort tasks. Drag the green arrow from the Sort task below Entity
Types Source onto the Merge Join. When prompted to edit the Input Output
Selection, for Input, select Merge Join Left. Repeat for the Sort task beneath
Entity as Merge Join Right.
13. Double-click the icon in the Merge Join task to open the Merge Join
Transformation Editor. In the top pane for the left sort check all of the inputs
except for CoNo. For the right Sort task, check only the PKey.
14. In the lower pane, locate the Input Column for PKey and change its Output Alias
to EntityPKey. The other rows will stay the same. Click OK.
15. From the toolbox, drag a Multicast data flow transformation task onto the
workspace below the Merge Join task. Connect the Merge Join with the Multicast
by dragging the green arrow from Merge Join onto Multicast.
To this point, your work in the Entity Type data flow should look like the top portion of
Exhibit 4. The next few steps will create the first of fourteen copies of the dataset we
need to import the roles from the de-normalized source database to the RBDMS.NET
Entity module. The pattern described below for the Oil Gas operator role is typical for
the other thirteen roles represented in the classic MS RBDMS database.
1. From the toolbar, drag a Conditional Split data flow transformation task onto the
lower left portion of the workspace and rename it OGO Split. Drag a green
arrow from the Multicast task onto the OGO split task to connect them.
9
4. Double-click the icon to open the Derived Column Transformation Editor.
In the lower pane of the Editor, for the Derived Column Name, enter Role. The
Derived Column will be <added as new column>. For Expression, enter “OGO”
and change the data type from Unicode string [DT_WSTR] to string [DT_STR].
Click OK.
5. From the toolbox, drag an OLE DB Destination task onto the workspace beneath
the Derived Column task and rename it Oper Destination. Drag the green arrow
from the Derived Column task onto the Oper Destination task to connect them.
6. Double-click the icon to open the OLE DB Destination Editor. In the OLE
DB Connection Manager, select your destination source MSRBDMS. Leave the
data access mode set as Table or view, and for the Name of the table, select
[dbo].[EntityAddress].
7. In the OLE DB Destination Editor, click Mappings and then match the input and
destination columns using the dropdown boxes as follows and then click OK.
a. <ignore> to PKey
b. Entity PKey to Entity Key
c. <ignore> to AddressKey
d. Role to Role
e. <ignore> to FirstName
f. <ignore> to LastName
g. <ignore> to Active
h. <ignore> to StartDate
i. <ignore> to EndDate
8. Save your work. Repeat steps 1 through 7 above for the other 13 roles (DRI, Cmt,
SVC, GGAT, GPUR, BULK, INJ, BOND, Log, Wtr, OTRAN, OPUR, and PLUG).
10
Develop the Entity Communications Data Flow
Finally, we will create the data flow definition for importing data into the
Communications table of the Entity module in RBDMS.NET. Again, the process will be
somewhat complex because of the need to import data from a de-normalized structure
into the more relational RBDMS.NET Entity module. The final Entity Communications
data flow is shown in Exhibit 5.
EXHIBIT 5.
Entity Communications Data Flow.
11
1. Return to the summary Control Flow and add a data flow task from the toolbox
to the workspace beneath EntityType. Rename the new data flow task Entity
Communications. Connect EntityType to Entity Communications by dragging
the green arrow from EntityType onto Entity Communications.
2. Double-click the icon on the Entity Communications data flow task to enter
the workspace to begin defining the steps in the flow.
3. Drag an OLE DB Source from the toolbox onto the workspace and rename it
tblRefCompany.
4. Double-click the icon to open the OLE DB Source Editor. The OLE DB
connection manager should be set to your source database MS_RBDMS. For the
Data access mode, select SQL command and either build or copy and paste the
following SELECT statement:
SELECT CoNo, Phone + ISNULL(N'x' + Ph_Ext, N'')
AS PhoneExt, Fax
FROM dbo.tblRefCompany
5. Check the Columns to make sure the external column and the output column are
aligned and click OK.
6. Next, add a Sort task beneath tblRefCompany and drag the green arrow from
tblRefCompany onto Sort to connect them.
7. Double-click the icon to open the Sort Transformation Editor. Check CoNo
and click OK.
8. Drag an OLE DB Source from the toolbox onto the workspace to the right of
tblRefCompany and rename it Entity.
9. Double-click the icon to open the OLE DB Source Editor. The OLE DB
connection manager should be set to your destination database MSRBDMS.
Leave the Data access mode set to Table or view and for the Name of the table,
select [dbo].[Entity].
10. In the OLE DB Source Editor, click Columns and in the list of Available External
Columns, uncheck everything except PKey and CoNo. Click OK.
11. Next, add a Sort task beneath Entity and drag the green arrow from Entity onto
Sort to connect them.
12
12. Double-click the icon to open the Sort Transformation Editor. Check CoNo
and click OK.
13. Add a Merge Join task from the toolbox below and between the two Sort tasks.
Drag the green arrow from the Sort task below Entity Types Source onto the
Merge Join. When prompted to edit the Input Output Selection, for Input, select
Merge Join Left. Repeat for the Sort task beneath Entity as Merge Join Right.
14. Double-click the icon in the Merge Join task to open the Merge Join
Transformation Editor. In the top pane for the left sort check all of the inputs
except for CoNo. For the right Sort task, check only the PKey.
15. In the lower pane, locate the Input Column for PKey and change its Output Alias
to EntityPKey. Change the Output Alias for PhoneExt to Phone. The Fax row will
stay the same. Click OK.
16. Add a Data Conversion task below the Merge Join task and use the green arrow
from Merge Join to connect it to Data Conversion.
17. Double-click the icon to open the Data Conversion Transformation Editor.
In the top pane, make sure that all of the fields are checked except EntityPKey. In
the lower pane, edit the Output Aliases by changing Copy of PhoneExt to
strPhone and Copy of Fax to strFax. Change the data types for each of the input
columns from Unicode string [DT_WSTR] to string [DT_STR]. Then click OK.
18. Add a Multicast task below the Data Conversion task and use the green arrow
from Data Conversion to connect to the Multicast.
19. From the toolbar, drag a Derived Column data flow transformation onto the
workspace below and to the left of the Multicast. Rename the Derived Column
task CommType PH. Drag the green arrow from the Multicast onto the
CommType PH to connect them.
20. Double-click the icon to open the Derived Column Transformation Editor.
In the lower pane of the Editor, for the Derived Column Name, enter
CommType. The Derived Column will be <added as new column>. For
Expression, enter “PH” and, for the data type, enter string [DT_STR]. Click OK.
21. Add an OLE DB Destination task to the workspace below the CommType PH
and connect the two tasks with the green arrow. Rename the OLE DB task
Communication PH. In the Properties pane, locate FastLoadOptions in the
Custom Properties list and turn off the TABLOCK;CHECK_CONSTRAINTS
option.
13
22. Double-click the icon to open the OLE DB Destination Editor. In the OLE
DB Connection Manager, select your destination source MSRBDMS. Leave the
data access mode set as Table or view, and for the Name of the table, select
[dbo].[Communication].
23. In the OLE DB Destination Editor, click Mappings and then match the input and
destination columns using the dropdown boxes as follows and then click OK.
a. <ignore> to PKey
b. Entity PKey to Entity Key
c. CommType to CommType
d. strPhone to CommAddress
e. <ignore> to TempID
f. <ignore> to Comment
Save your work. Then begin again at the Multicast task you added above Comm Type
PH.
1. From the toolbar, drag a Conditional Split data flow transformation task onto the
lower portion of the workspace to the right of CommType PH. Drag a green
arrow from the Multicast task onto the Conditional Split task to connect them.
14
pane, locate FastLoadOptions in the Custom Properties list and turn off the
TABLOCK;CHECK_CONSTRAINTS option.
6. Double-click the icon to open the OLE DB Destination Editor. In the OLE
DB Connection Manager, select your destination source MSRBDMS. Leave the
data access mode set as Table or view, and for the Name of the table, select
[dbo].[Communication].
7. In the OLE DB Destination Editor, click Mappings and then match the input and
destination columns using the dropdown boxes as follows and then click OK.
a. <ignore> to PKey
b. Entity PKey to Entity Key
c. CommType to CommType
d. strFax to CommAddress
e. <ignore> to TempID
f. <ignore> to Comment
8. Save your work.
15