Home Cloud & Networking Microsoft SQL Server 2012 Integration Services: An Expert Cookbook

Microsoft SQL Server 2012 Integration Services: An Expert Cookbook

By Reza Rad , Pedro Perfeito , Pedro M Perfeito and 1 more
books-svg-icon Book
Subscription FREE
eBook + Subscription €14.99
eBook €28.99
Print + eBook €37.99
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
Subscription FREE
eBook + Subscription €14.99
eBook €28.99
Print + eBook €37.99
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
  1. Free Chapter
    Getting Started with SQL Server Integration Services
About this book
SQL Server Integration Services (SSIS) is a leading tool in the data warehouse industry - used for performing extraction, transformation, and load operations. This book is aligned with the most common methodology associated with SSIS known as Extract Transform and Load (ETL); ETL is responsible for the extraction of data from several sources, their cleansing, customization, and loading into a central repository normally called Data Warehouse or Data Mart.Microsoft SQL Server 2012 Integration Services: An Expert Cookbook covers all the aspects of SSIS 2012 with lots of real-world scenarios to help readers understand usages of SSIS in every environment. Written by two SQL Server MVPs who have in-depth knowledge of SSIS having worked with it for many years.This book starts by creating simple data transfer packages with wizards and illustrates how to create more complex data transfer packages, troubleshoot packages, make robust SSIS packages, and how to boost the performance of data consolidation with SSIS. It then covers data flow transformations and advanced transformations for data cleansing, fuzzy and term extraction in detail. The book then dives deep into making a dynamic package with the help of expressions and variables, and performance tuning and consideration.
Publication date:
May 2012
Publisher
Packt
Pages
564
ISBN
9781849685245

 

Chapter 1. Getting Started with SQL Server Integration Services

by Reza Rad and Pedro Perfeito

In this chapter, we will cover the following topics:

  • Import and Export Wizard: First experience with SQL Server Integration Services (SSIS)

  • Getting started with SSDT

  • Creating the first SSIS package

  • Getting familiar with Data Flow Task

  • SSIS 2012 versus previous versions in Developer Experience

 

Introduction


As technology evolves, it is always necessary to integrate data between different systems. The integration component is increasingly gaining importance, especially the component responsible for data quality as well as the cleaning rules applied between source and destination databases. Different vendors have their own integration tools and components, and Microsoft with its SSIS tool is recognized as one of the leaders in this field.

SSIS can be used to perform a broad range of data integration tasks, and the most common scenarios are applied to Data Warehousing. The known term associated with Data Warehousing is the Extract Transform and Load (ETL) that is responsible for the extraction of data from several sources, their cleansing, customization, and loading into a central repository (for example, to a Data Warehouse, Data Mart, Hub, and so on). SSIS is also used in other scenarios, for example data migration and data consolidation. Data Migration is the one-time movement of data between databases and computer systems, and is needed when changes occur or when we upgrade our systems. Data Consolidation combines and integrates data from disparate systems and assumes high importance in a business environment with increasing acquisitions and mergers. The following diagram adapted from TDWI (www.tdwi.org) helps clarify the different scenarios where SSIS could be used:

New business challenges are driving organizations to adopt data integration projects. Some of these challenges are:

  • Increasing demand for real-time information reporting and analysis

  • Large volumes of data spread along the entire organization

  • The need to comply with regulations, which often require to continuously track all changes to data and not just the net result of those changes

Although SSIS is an amazing tool for data integration, the same work can be done manually in almost all cases. As you can imagine, performing data integration tasks manually could be hard to maintain in terms of code, hard to scale properly, and would require more time to implement. From our perspective, since we have SSIS, there is no real reason to do it manually. The cost of ownership is not a problem either, because SSIS is included with SQL Server licenses that most organizations have already acquired.

In this chapter you will learn how to work with SSIS, how to create packages for data transfer, and you'll perform some simple operations with SSIS Package. At the end, we will highlight several improvements which are included in this new version.

Note

As we will cover many recipes in this book, it is advisable to have Adventure Works SQL 2012 sample database installed.

 

Import and Export Wizard: First experience with SSIS


The Import and Export Wizard will be our first stop at SSIS. This wizard provides a simple ETL and is easy to use for basic data transfer operations. With this wizard you can choose a source, a destination, and map columns with few constraints on data transfer options. We will take a brief look at this wizard in our first experience with SSIS.

Getting ready

Install SQL Server 2012. SQL Server 2012 comes with three editions: Standard, Business Intelligence, and Enterprise. The Business Intelligence edition covers all requirements for this book that you'll need to install. With this edition you will have all SQL Server Integration Services features.

For many recipes in this book, you need to have the AdventureWorks2012 and AdventureWorksLT2012 sample databases installed. Information about installing these databases can be found in the book introduction.

To install sample databases, first download the database files from http://msftdbprodsamples.codeplex.com and then open SSMS to execute this statement (download AdventureWorks2012 Data File and AdventureWorksLT2012_Data):

"" CREATE DATABASE AdventureWorks2012 ON (FILENAME = '<drive>:\<file path>\AdventureWorks2012_Data.mdf') FOR ATTACH_REBUILD_LOG ;""
CREATE DATABASE AdventureWorksLT2012 ON (FILENAME = '<drive>:\<file
path>\AdventureWorksLT2012_Data.mdf') FOR ATTACH_REBUILD_LOG ;

Note that you should replace the path of the file here with the path of the file downloaded on your machine.

Create a new database in SQL Server. Open SQL Server Management Studio (SSMS) from Start Menu | Microsoft SQL Server 2012 | SQL Server Management Studio. In the SSMS, connect to local computer instance and create a new database. Name this database as PacktPub_SSISbook.

Note that you should run SSMS as administrator, to do this just right click on SQL Server Management Studio from path above and right click on it and choose Run as Administrator.

How to do it...

  1. Open the Import and Export Wizard; there are three ways you could do it:

    • In the Run window, enter DtsWizard.

    • Open the wizard from the following address: Start Menu | All Programs | Microsoft SQL Server 2012 | Import and Export Data.

    • In SSMS, right-click on any database and then under Tasks, select Import Data or Export Data.

  2. At the first step in the Import and Export Wizard, a welcome page will appear. Click on Next to enter the Choose a Data Source step, in this step you should choose where the Data Source comes from. The Data Source can be any source; from an Oracle database or SQL Server to any other database, flat files (such as .txt and .csv) or even Excel files, the range of source and destinations is based on data providers installed on the machine. For this sample, leave the Data Source option as its default option which is SQL Server Native Client 11.0.

  3. We want to export two tables from the AdventureWorks2012 database to another database. Therefore, leave the Server name as (local) or a single dot ( . ) or if you have a named instance you could use .\<Instance-Name>, and in the Authentication section leave the Authentication Type as Windows Authentication. This option will use your Windows account for connecting to the database, so obviously the Windows account should have read access to the underlying database.

  4. In the Database drop-down box, select AdventureWorks2012 from the list. Then click on Next and go to the next step.

  5. The next step is required to choose a Destination, therefore, provide the connection details of the data's destination (types of destinations can differ from databases to flat files). For this sample leave the destination as default value which is SQL Server Native Client 11.0.

  6. Set the Server Name to (local) or dot ( . ) to connect default instance of current machine. Set the Authentication as Windows Authentication. Select R1.1 in the Database drop-down list . Then click on Next to follow the wizard's steps.

  7. In the Specify Table Copy or Query step you can choose between selecting a table or view name for a source database or writing a query to fetch data from a source. For this example, choose the Copy data from one or more tables or views option .

  8. Next, a list of tables and views from the source database will appear. For this example, select HumanResource.Department, Person.Address, and Production.Product. Then click on Next.

  9. The Save and Run Package step is next; it provides the ability to save all the settings and configurations that you've set for an SSIS Package. We are going to save this package to see what the SSIS Package looks like. There are a lot of concepts and options associated with saving SSIS Packages which will be discussed in upcoming chapters, so don't worry about some terminologies here, all of them will be explored later. Check the Save SSIS Package option and click on the Next button .

  10. In the next step which is the Save SSIS Package dialog , type the name as R01_ImportExportWizard, and choose a location for the package file. Then click on Next.

  11. Now a summary of all settings that you've done appears here; after reviewing the summary click on Finish.

  12. After clicking on the Finish button , the Import and Export Wizard will show up and we can see all the messages generated during the package's execution. The number of rows copied are displayed, or any other information such as the number of rows transferred, validated, and any other actions.

  13. Open and see the execution's report by clicking on the Report button .

  14. Close the Wizard and open SSMS to check the destination database, you can see transferred tables there with data.

How it works...

In this recipe, we created the first SSIS Package with the Import and Export Wizard, this simple scenario exports some tables from the AdventureWorks database to an empty database. In the last few steps, we saved the whole data transfer scenario to an SSIS Package on a file system that we'll be able to open with SQL Server Data Tools (SSDT) in later recipes.

With the Import and Export Wizard you can import or export data from a source to a destination, this is the most simplistic ETL scenario. In the Select a Data Source step you perform the Extract part of ETL and fetch data from SQL server database (data source). The second step, which was the Destination Select, was configured during the Load part of ETL. Load indicates where data should be exported; we export data to a SQL Server database. In this first example scenario we don't have any specific Transform stage. We will see this part of the ETL later, during the Data Flow chapters of this book.

When you choose table(s) from the AdventureWorks database in the Select Source Tables or Views section , tables that don't already exist in the destination database will first be created.

After matching the columns and metadata, data will be transferred and a summary of all logs will show what happened during execution.

We saved this package to the file system; we can also save packages to an SQL Server. The difference between the different storage options for SSIS Packages with their pros and cons will be explored later in Deployment chapters.

There's more...

As you've seen so far, the Import and Export Wizard is a simple way to transfer data that covers our most basic requirements. But in real-world scenarios, you need some additional features, which we'll now discuss.

Mapping columns

In the Select Source Tables and Views step, when you select a table or view to transfer, an Edit Mappings button will be enabled. Note that you need to select a row in order to enable this button.

When you click on Edit Mappings, the Column Mappings window will appear. As you see, there are some options here for mapping Source and Destination columns.

When the destination table doesn't exist in the destination database, the Create Destination Table step will flag it. This means that the missing table will be created in the destination database; you can click on the Edit SQL button to see what the exact create table statement is; you can change the script as you want here.

When the destination table already exists in the destination database, the Delete Rows and Append Rows options in Destination Table will be selectable. You can select between deleting rows in a destination table before data transfer or appending new rows to existing records with these options.

The Drop and re-create destination table option will be selectable when the destination table already exists. Another important option is Enable identity insert , which should be checked if you load data into an IDENTITY column. The last part of the Column Mappings window is the Mappings section, which shows Source and Destination columns , as well as some additional column information. By default, all columns with the same name in Source and Destination will be mapped automatically. However, if the column names are different you should select columns by selecting the correct column name in the drop-down box. If you want to remove a column from data transfer you can simply choose the <ignore> option .

Configure transfer settings for multiple tables

In real-world scenarios, you need to configure transfer settings for all tables at once. Select multiple rows in the Select Source Tables or Views Wizard step by holding the Ctrl key and clicking on every row that you need, and then click on the Edit Mappings button. The Transfer Settings dialog box will open; all configurations that you set here will be applied to all selected tables.

In the Destination schema name you can choose a schema name from the destination database and use this schema for all selected tables. You can also type a schema name there; if that schema doesn't exist in the destination database it will be created and all tables will be created under this new schema. The Drop and recreate new destination tables option will be applied to all new tables, and the Delete rows in existing destination tables option will be applied to all existing tables. Enable identity insert is also applicable to all tables that have Identity columns.

Mapping data types

Data types which are automatically mapped through the Column Mappings window of the Import and Export Wizard are defined in XML files based on source and destination type. A list of all these XML files is available here:

<system drive>:\Program Files\Microsoft SQL Server\110\DTS\MappingFiles

There is a mapping file for each source or destination, and details of data type mappings can be found there. The next screenshot shows a portion of the MSSql8toOracle8 mapping file:

Querying the source database

If you need the ability to provide a custom query to read data from the source table(s), you can choose to write a query in order to specify the data to be transferred, and in the next step write the query to fulfill your requirements. You can also open a query from a file.

See also

  • Creating the first SSIS Package

  • Getting familiar with Data Flow Task

       
About the Authors
  • Reza Rad

    Reza Rad has more than 10 years’ experience in databases and software applications, and majority of his work experience was in data warehousing and Business Intelligence. He started to work with Microsoft technologies from SQL Server 7 with Visual Basic 6. He has a bachelor degree in Computer Engineering. Reza is a DW / BI architect and consultant. He worked with large enterprises around the world and delivered high quality data warehousing and BI solutions for them. He worked with industries such as Health, Finance, Logistics, Sales, Order Management, Manufacturing, Telecommunication, and so on. Reza has been awarded Microsoft Most Valuable Professional in SQL Server, 2011. Reza is an international speaker at SQL Server, BI, and DW conferences around the world. He speaks in SQL PASS Summits, Microsoft TechEd, SQL Saturdays, SQL Server user groups, and code camps. He also wrote some books on SQL Server and databases; one of the most recent books is Packt’s SQL Server 2012 Integration Services: An Expert Cookbook. Reza is a big fan of data-related technologies. His expertise is in EIM, ETL, Data Governance, Big Data, Data Warehousing, BI, Data Visualization, Master Data Management, and OLAP. Reza is the author of the Webcast series on the RADACAD website (http://www.radacad.com). He also writes articles and blog posts in his technical blog (http://www.rad.pasfu.com), where he writes about most of Microsoft technologies such as SSIS, MDS, DQS, SSAS, Power BI, and HDInsight. His blog contains the latest information about his presentations and publications. Reza is a mentor and Microsoft Certified Trainer. He has been in the professional training business for many years. He does lots of 400 handed level training for many enterprises around the world via remote or in-person training. Reza is an active member in MSDN forums especially on SQL Server, and Power BI area. He is also the leader of the New Zealand Data Warehousing and Business Intelligence user group which is a registered chapter of PASS.

    Browse publications by this author
  • Pedro Perfeito

    Pedro was born in 1977 in Portugal and currently works as BI Senior Consultant and Developer at Novabase. Hes also an invited teacher in master and postgraduate BI degrees, by IUL-ISCTE (Lisbon) and by Universidade Portucalense (UPT-Porto) respectively. He received in 2010 and 2011 the Microsoft award Microsoft Most Valuable Professional (MVP) for all his dedication and contribution helping theoretical and practical issues in the various BI communities and hes also co-author of the SQL MVP Deep Dives book 2Edition. He has several Microsoft certifications including MCP, MCSD, MCTS-Web, MCTS-BI and MCITP-BI and also worldwide certifications in the area of BI provided by TDWI/CBIP (The Data Warehouse Institute http://www.tdwi.org). Hes currently preparing his PhD degree on BI. For further details you can also visit his personal blog at http://www.pedrocgd.blogspot.com or even contact him directly at pperfeito@hotmail.com

    Browse publications by this author
  • Pedro M Perfeito

    Pedro was born in 1977 in Portugal and currently works as BI Senior Consultant and Developer at Novabase. He’s also an invited teacher in master and postgraduate BI degrees, by IUL-ISCTE (Lisbon) and by Universidade Portucalense (UPT-Porto) respectively. He received in 2010 and 2011 the Microsoft award “Microsoft Most Valuable Professional” (MVP) for all his dedication and contribution helping theoretical and practical issues in the various BI communities and he’s also co-author of the SQL MVP Deep Dives book – 2Edition. He has several Microsoft certifications including MCP, MCSD, MCTS-Web, MCTS-BI and MCITP-BI and also worldwide certifications in the area of BI provided by TDWI/CBIP (The Data Warehouse Institute – http://www.tdwi.org). He’s currently preparing his PhD degree on BI. For further details you can also visit his personal blog at http://www.pedrocgd.blogspot.com or even contact him directly at pperfeito@hotmail.com

    Browse publications by this author
  • Abolfazl Radgoudarzi
Latest Reviews (3 reviews total)
Good, some errors found, but good enough for me
Good book easy to understand and to setup the test system
A fantastic book. A good way to learn the basis of SSIS. A fantastic book
Microsoft SQL Server 2012 Integration Services: An Expert Cookbook
Unlock this book and the full library FREE for 7 days
Start now