Interactive #2 SSIS - Lab 1 exercise PDF

Title Interactive #2 SSIS - Lab 1 exercise
Course Datawarehousing
Institution Seneca College
Pages 21
File Size 1.6 MB
File Type PDF
Total Downloads 61
Total Views 165

Summary

Lab 1 exercise...


Description

SSIS Packages Interactive exercise # 2 Introduction In this lesson, you create a simple ETL package that extracts data from a single flat file source, transforms the data using two lookup transformations, and writes the transformed data to a copy of the FactCurrencyRate fact table in the AdventureWorksDW2017 sample database. This exercise is based on Microsoft tutorial “Create a project and basic package with SSIS https://docs.microsoft.com/en-us/sql/integration-services/lesson-1-create-a-project-and-basic-packagewith-ssis?view=sql-server-2017 Pre-requisites Before we start, we need to: 1. Templates for visual studio, these depend on visual studio version: a. For 2019: Download and configure the SSIS Integration templates for visual studio from Microsoft market place: https://marketplace.visualstudio.com/items? itemName=SSIS.SqlServerIntegrationServicesProjects&ssr=false#overview b. For 2017 : Download and install the SQL Server Data Tools, see Download SQL Server Data Tools. 2- Install and deploy the AdventureWorksDW2017 sample database: Install and configure AdventureWorks sample database - SQL. Download the adventurworksDW2017.bak from the link then move the file to SQL backup library

Use Microsoft management studio to install the adventure works database to the Local data base on your machine.

Right click and select restore database

You should get a confirmation screen as follows

Click ok to restore. Just to check expand the database and you should see the Adeventureworks2017DW database and the tables Expand one or two table to check the data.

3- To download all of the lesson packages for this tutorial: 1. 2. 3. 4.

Navigate to Integration Services tutorial files. Select the DOWNLOAD button. Select the Creating a Simple ETL Package.zip file, then select Next. After the file downloads, unzip its contents to a local directory.

Steps

In visual studio 2017 or 2019

Select “Integration Service Project” and create a new project name it SSIS_package_firstname

Right click on the package name and rename it to firstname_lesson1 (where first name is your name)

Create a flat file connection 1.

2. 3.

In the Solution Explorer pane, right-click on Connection Managers and select New Connection Manager. In the Add SSIS Connection Manager dialog, select FLATFILE, then Add. In the Flat File Connection Manager Editor dialog box, for Connection manager name, enter Sample Flat File Source Data.

4.

Select Browse.

5.

In the Open dialog box, locate the SampleCurrencyData.txt file on your computer.

6.

Clear the column names in the first data row checkbox.

7. Set locale-sensitive properties a. In the Flat File Connection Manager Editor dialog box, select General. b. Set Locale to English (United States) and Code page to 1252. 8. Rename columns in the Flat File connection manager a. In the Flat File Connection Manager Editor dialog box, select Advanced. b. In the property pane, make the following changes: oChange the Column 0 name property to AverageRate_firstname oChange the Column 1 name property to CurrencyID_firstname. oChange the Column 2 name property to CurrencyDate_firstname. oChange the Column 3 name property to EndOfDayRate_firstname. Below an example of renaming the first screen:

9. Remap column data types By default, all four of the columns are initially set to a string data type [DT_STR] with an OutputColumnWidth of 50. 1.

In the Flat File Connection Manager Editor dialog box, select Suggest Types. Integration Services automatically suggests appropriate data types based on the first 200 rows of data. You can also change these suggestion options to sample more or less data, to specify the default data type for integer or Boolean data, or to add spaces as padding to string columns. For now, make no changes to the options in the Suggest Column Types dialog box, and select OK to have Integration Services suggest data types for columns. This action returns you to the Advanced pane of the Flat File Connection Manager Editor dialog box, where you can view the column data types suggested by Integration Services. Alternately, if you select Cancel, no suggestions are made to column metadata and the default string (DT_STR) data type is used. In this tutorial, Integration Services suggests the data types shown in the second column of the following table for the data from the SampleCurrencyData.txt file. The fourth column provides the data types required for the columns in the destination, which are defined in a subsequent step.

Flat File column

Suggested type

Destination column

Destination type

AverageRate

float [DT_R4]

FactCurrencyRate.AverageRate

float

CurrencyID

string [DT_STR]

DimCurrency.CurrencyAlternateKey

nchar(3)

CurrencyDate

date [DT_DATE]

DimDate.FullDateAlternateKey

date

EndOfDayRate

float [DT_R4]

FactCurrencyRate.EndOfDayRate

float

The data type suggested for the CurrencyID column is incompatible with the data type of the field in the destination table. Because the data type of DimCurrency.CurrencyAlternateKey is nchar(3), CurrencyID must be changed from string [DT_STR] to Unicode string [DT_WSTR]. In addition, the field DimDate.FullDateAlternateKey is defined as a date data type, so the type for CurrencyDate needs to be changed from date [DT_Date] to database date [DT_DBDATE]. 2.

In the list, select the CurrencyID column and in the property pane, change the Data Type of column CurrencyID from string [DT_STR] to Unicode string [DT_WSTR].

3.

4.

In the property pane, change the data type of column CurrencyDate from date [DT_DATE] to database date [DT_DBDATE]. Select OK.

Create an OLE DB connection 1.

In the Solution Explorer pane, right-click on Connection Managers and select New Connection Manager.

2.

In the Add SSIS Connection Manager dialog, select OLEDB, then select Add.

3.

In the Configure OLE DB Connection Manager dialog box, select New.

4.

For Server name, enter localhost.

When you specify localhost as the server name, the connection manager connects to the default instance of SQL Server on the local computer. To use a remote instance of SQL Server, replace localhost with the name of the server to which you want to connect. 5.

In the Log on to the server group, verify that Use Windows Authentication is selected.

6.

In the Connect to a database group, in the Select or enter a database name box, type or select AdventureWorksDW2017.

7.

Select Test Connection to verify that the connection settings you have specified are valid.

8.

Select OK.

9.

Select OK.

10.

In the Connection Managers pane, verify that localhost.AdventureWorksDW2017is selected.

Add a data flow task to the package After you've created the connection managers for the source and destination data, you add a Data Flow task to your package. The Data Flow task defines the data flow engine that moves data between sources and destinations, and provides the functionality for transforming, cleaning, and modifying data as it is

moved. The Data Flow task is where most of the work of an extract, transform, and load (ETL) process occurs. Add a Data Flow task 1. 2.

Select the Control Flow tab. In the SSIS Toolbox pane, expand Favorites, and drag a Data Flow Task onto the design surface of the Control Flow tab. Note: If the SSIS Toolbox isn't available, select the SSIS menu, and then select SSIS Toolbox to display it. 3. On the Control Flow design surface, right-click the new Data Flow Task, select Rename, and change the name to Extract Sample Currency Data_firstname. Where first name is your first name.

Note: Provide unique names for all components that you add to a design surface. For ease of use and maintainability, the names should describe the function of each component. Following these naming guidelines allows your Integration Services packages to be self-documenting. Right-click the Data Flow task, select Properties, and in the Properties window, verify that the LocaleID property is set to English (United States). Add a Flat File source component 1.

To open the Data Flow designer, either double-click on the Extract Sample Currency Data data flow task, or select the Data Flow tab. 2. In the SSIS Toolbox, expand OtherSources, and then drag a Flat File Source onto the design surface of the Data Flow tab.

3.

On the Data Flow design surface, right-click the newly added Flat File Source, select Rename, and change the name to Extract Sample Currency Data_firstname where first name is your first name. 4. Double-click the Flat File source to open the Flat File Source Editor dialog. 5. In the Flat file connection manager field, select Sample Flat File Source Data. 6. Select Columns and verify that the names of the columns are correct.

7. 8.

Select OK. Right-click the Flat File source and select Properties. In the Properties window, verify that the LocaleID property is set to English (United States).

Lookup transformations After you have configured the Flat File source to extract data from the source file, you define the Lookup transformations needed to obtain the values for CurrencyKey and DateKey. A Lookup transformation performs a lookup by joining data in the specified input column to a column in a reference dataset. The reference dataset can be an existing table or view, a new table, or the result of an SQL statement. In this tutorial, the Lookup transformation uses an OLE DB connection manager to connect to the database that contains the source data of the reference dataset. In this task, you add and configure the following two Lookup transformation components to the package: 

One transformation that does a lookup of values from the CurrencyKey column of the DimCurrency dimension table, based on matching CurrencyID column values from the flat file.



One transformation that does a lookup of values from the DateKey column of the DimDate dimension table, based on matching CurrencyDate column values from the flat file.

In both cases, the Lookup transformation uses the OLE DB connection manager you previously created. 1.

In the SSIS Toolbox, expand Common, and then drag Lookup onto the design surface of the Data Flow tab. Place Lookup directly below the Extract Sample Currency Data source. 2. Select the Extract Sample Currency Data flat file source and drag its blue arrow onto the newly added Lookup transformation to connect the two components.

3.

On the Data Flow design surface, select Lookup in the Lookup transformation, and change the name to Lookup Currency Key_firstname where firstname is your first name. 4. Double-click the Lookup Currency Key transformation to display the Lookup Transformation Editor. 5. On the General page, make the following selections: a. Select Full cache. b. In the Connection type area, select OLE DB connection manager.

2.

On the Connection page, make the following selections:

a) In the OLE DB connection manager dialog box, ensure that that localhost.AdventureWorksDW2017 is displayed. b) Select Use results of an SQL query, and then enter or paste the following SQL statement: SQLCopy SELECT * FROM [dbo].[DimCurrency] WHERE [CurrencyAlternateKey]

IN ('ARS', 'AUD', 'BRL', 'CAD', 'CNY', 'DEM', 'EUR', 'FRF', 'GBP', 'JPY', 'MXN', 'SAR', 'USD', 'VEB') c) Select Preview to verify the query results.

1. On the Columns page, make the following selections: a) In the Available Input Columns panel, drag CurrencyID_firstname to the Available Lookup Columns panel and drop it on CurrencyAlternateKey. b) In the Available Lookup Columns list, select the check box to the left of CurrencyKey.

a. Select OK to return to the Data Flow design surface. b. Right-click the Lookup Currency Key transformation and select Properties. c. In the Properties window, verify that the LocaleID property is English (United States) and the DefaultCodePage property is 1252.

Add and configure the Lookup Date Key transformation 1.

In the SSIS Toolbox, drag Lookup onto the Data Flow design surface. Place this Lookup directly below the Lookup Currency Key_firstname transformation. 2. Select the Lookup Currency Key_firstname transformation and drag its blue arrow onto the new Lookup transformation to connect the two components. 3. In the Input Output Selection dialog, select Lookup Match Output in the Output list box, and then select OK.

4.

On the Data Flow design surface, select the name Lookup in the newly added Lookup transformation and change that name to Lookup Date Key_firstname where firstname is your firstname. 5. Double-click the Lookup Date Key transformation. 6. On the General page, select Partial cache. 7. On the Connection page, make the following selections: a. In the OLEDB connection manager dialog, ensure that localhost.AdventureWorksDW2017 is displayed. b. In the Use a table or view box, enter or select [dbo].[DimDate].

2.

On the Columns page, make the following selections:

a) In the Available Input Columns panel, drag CurrencyDate_firstname to the Available Lookup Columns panel and drop it on FullDateAlternateKey. If you see a message indicating a data type mismatch, change the data type of CurrencyDate to [DT_DBDATE].

(Note: If the datatype change does not reflect, change it at the level of the package source code. Open the dtsx file using a text editor or notepad (it is an xml file), select for the Flat File Sourcepart, find and replace Data types.) b) In the Available Lookup Columns list, select the check box to the left of DateKey. a. On the Advanced page, review the caching options. b. Select OK to return to the Data Flow design surface. c. Right-click the Lookup Date Key transformation and select Properties.

d. In the Properties window, verify that the LocaleID property is English (United States)and the DefaultCodePage property is 1252. Add and configure the sample OLE DB destination 1. In the SSIS Toolbox, expand Other Destinations, and drag OLE DB Destination onto the design surface of the Data Flow tab. Place the OLE DB Destination directly below the Lookup Date Key firstname transformation. 2. Select the Lookup Date Key transformation and drag its blue arrow over to the new OLE DB Destination to connect the two components together. 3. In the Input Output Selection dialog, in the Output list box, select Lookup Match Output, and then select OK. 4. On the Data Flow design surface, select the name OLE DB Destination in the new OLE DB Destination component, and change that name to Sample OLE DB Destination_firstname where first name is your firstname. 5. Double-click Sample OLE DB Destination. 6. In the OLE DB Destination Editor dialog, ensure that localhost.AdventureWorksDW2017 is selected in the OLE DB Connection manager box. 7. In the Name of the table or the view box, enter or select [dbo].[FactCurrencyRate].

8. Select the New button to create a new table. Change the name of the table in the script from Sample OLE DB Destination to NewFactCurrencyRate_firstname where firstname is your firstname . Select OK.

9. Upon selecting OK, the dialog closes and the Name of the table or the view automatically changes to NewFactCurrencyRate. 10. Select Mappings. 11. Verify that the AverageRate, CurrencyKey, EndOfDayRate, and DateKey input columns are mapped correctly to the destination columns. If same-named columns are mapped, the mapping is correct.

12. Select OK. 13. Right-click the Sample OLE DB Destination destination and select Properties. 14. In the Properties window, verify that the LocaleID property is set to English (United States) and the DefaultCodePage property is set to 1252 Test the package

1.

On the Debug menu, select Start Debugging. The package runs, resulting in 1,096 rows successfully added into the NewFactCurrencyRate fact table in AdventureWorksDW2017. To verify this result, select the Data Flow tab. 2. After the package has completed running, on the Debug menu, select Stop Debugging.

1. Launch Microsoft management tools and connect to the local database engine. 2. Select AdventureworksDW2017 and expand tables 3. You should see the new currency fact table, right click and select top 1000 rows....


Similar Free PDFs