Documente Academic
Documente Profesional
Documente Cultură
Microsoft Integration Services provides the SQL Server Import and Export Wizard for building packages that perform data transfers. These packages can extract data from a source and load it into a destination, but the package can perform only minimal data transformation in the transfer process. In addition, the wizard is a quick way to create basic packages that can then be enhanced in SSIS Designer. In this tutorial, you will learn how to use the SQL Server Import and Export Wizard to create a basic package. The package that you create extracts data from an Excel workbook and loads it into a table in the AdventureWorks2008R2 database. The table is defined as one of the steps in the wizard and then created dynamically when you run the package. In subsequent lessons, the package will be expanded to include a data flow that sorts the data, creates a new column, and populates the column with values. To generate the new values, you will learn how to use the new Integration Services expression language together with the graphical expression builder to write an expression that creates new values based on existing data columns. When you install the sample data that the tutorial uses, you also install the completed versions of the packages for each lesson of the tutorial. By using the completed lesson 1 package, you can skip ahead and begin the tutorial with lesson 2 if you like. If this is your first time working with packages, the SQL Server Import and Export Wizard, or the new development environment, we recommend that you begin with lesson 1.
Requirements
This tutorial is intended for users familiar with fundamental database operations, but who have limited exposure to the new features available in SQL Server Integration Services. To use this tutorial, your system must meet the following requirements: You must run the package that this tutorial creates in 32-bit mode. This sample uses the Microsoft Jet 4.0 OLE DB provider, for which there is no 64-bit version. The package fails if you run it in 64-bit mode. For more information about running packages in 32-bit mode on a 64-bit computer, see 64 bit Considerations for Integration Services.
SQL Server with the AdventureWorks2008R2 database must be installed on the computer. To enhance security, the sample databases are not installed by default. To install the sample databases, see Considerations for Installing SQL Server Samples and Sample Databases. You must have permission to create and drop tables in AdventureWorks2008R2. The sample data must be installed on the computer. The sample data is installed together with the samples. If you cannot find the sample data, return to the procedure above and complete installation as described.
Note
When reviewing tutorials it is recommended you add Next and Previous buttons to the document viewer toolbar and Previous Buttons to Help.
This tutorial assumes that you have not reconfigured SSIS Designer to use auto-connect features between control flow elements or between data flow elements. If SSIS Designer uses auto-connect, an element may be connected automatically when added to the design surface. Also, the auto-connect feature for control flow supports the use of Failureand Completion as the default constraint, instead of Success. If SSIS Designer is not using Success as its default constraint, you should reset this configuration while doing the tutorial. You configure the auto-connect features in the Business Intelligence Designers section in the Options dialog box that is available from Options on the Tool menu. Estimated time to complete this tutorial: 1 hour
In this lesson, you will create a basic package by using the SQL Server Import and Export Wizard. The package selects and extracts data from an Excel spreadsheet and writes that data to the ProspectiveCustomers table in the AdventureWorks2008R2 sample database. The table is defined in the wizard and created when you run the package. The SQL Server Import and Export Wizard will be run in Business Intelligence Development Studio and you will launch the wizard from an Integration Services project. After you complete the SQL Server Import and Export Wizard the package is added to the Integration Services project. You will open the package in SSIS Designer, the Integration Services graphical tool for building complex packages, and verify that certain properties of the package are configured correctly. Finally, you will test the package by running it in Business Intelligence Development Studio.
Important
This tutorial requires the AdventureWorks2008R2 sample database. For more information on installing and depl see Considerations for Installing SQL Server Samples and Sample Databases.
Lesson Tasks
This lesson contains the following tasks: Step 1: Creating the Integration Services Project Step 2: Running the Wizard to Create the Basic Package Step 3: Testing the Lesson 1 Basic Package
This tutorial uses the SQL Server Import and Export Wizard to create a basic package by running the wizard in Business Intelligence Development Studio. The wizard is launched from an Integration Services project. In this task you will create an Integration Services project.
In this task, you will run the SQL Server Import and Export Wizard to create the basic data transfer package. Specify the data source. You will use the Excel workbook, Customers.xls, as the data source. On a wizard page you will provide a query that selects the customers who own at least one car from the Customers spreadsheet in the workbook.
Specify the destination. You will write the data to a table in the AdventureWorks2008R2 database. The table, ProspectiveCustomers, will be created dynamically. You will define the metadata of the destination columns by using the wizard.
After the wizard completes, you will rename the package and verify the values of certain locale-sensitive properties of the package, tasks, source, and destination. This step is important because the Excel workbook includes locale-sensitive date data in the BirthDate column. If the regional settings on your computer do not specify English (United States), you must update the values of the specified properties or the package cannot be run successfully.
5.
In the Destination list, click [dbo].[Query], and then change the table name, Query, to ProspectiveCustomers. b. To edit column metadata and table options, click Edit Mappings. 10. On the Columns Mappings page, do the following steps: a. Verify that the Create Destination table option is selected, select the Drop and recreate destination table check box, and modify the metadata of the destination columns. The following table lists the columns and the metadata changes that you need to make:
a.
Column name
FirstName MiddleIntial LastName BirthDate MaritalStatus Gender EmailAddress YearlyIncome TotalChildren NumberChildrenAtHome Education Occupation HouseOwnerFlag NumberCarsOwned AddressLine1 AddressLine2 City
Default type
nvarchar nvarchar nvarchar datetime nvarchar nvarchar nvarchar float float float nvarchar nvarchar float float nvarchar nvarchar nvarchar
Updated type
No change nchar No change No change nchar nchar No change money tinyint tinyint No change No change bit tinyint No change No change No change
b. Click OK. 11. On the Review Data Type Mapping page, accept the default settings and click Next. 12. On the Complete the Wizard page, review information about the new package and click Finish. 13. On the Performing Operations page, view the actions that the wizard performs. When finished, the Status column for each action should display Success. 14. Click Close. 15. In Solution Explorer, right-click the new package in the SSIS Packages folder, click Rename, and type Basic Package Lesson 1. Make sure that the name includes the .dtsx extension. 16. If asked whether to rename the object as well, click Yes.
In this lesson, you have done the following tasks: Created a new Integration Services project. Run the SQL Server Import and Export Wizard to create the basic package. Verified and updated the values of locale sensitive properties.
Important
The first time you run the package, the task named Drop table(s) SQL Task will fail. This behavior is expected. T attempts to drop and re-create the ProspectiveCustomers table; however, the first time that the package runs the t fails. This does not cause the package to fail because the precedence constraint between the Drop table(s) SQL T to Completion rather than Success.
Before you test the package you should verify that the control and data flows in the lesson 1 package, Basic Package Lesson 1.dtsx, contain the objects shown in the following diagrams. Control Flow
Data Flow
Also, the package should include the following two connection managers. One connects to the Excel workbook file Customers.xls and the other one connects to the AdventureWorks2008R2 database.
In Lesson 1: Creating the Basic Package, you used the SQL Server Import and Export Wizard to get a quick start on a basic Integration Services package. The package has limited functionality; it only extracts data from an Excel workbook file and loads the data into the ProspectiveCustomers table of the AdventureWorks2008R2 sample database. Typically, a package also needs to manipulate and transform the data. Integration Services provides a wealth of transformations that you can use to copy, cleanse, modify, sort, and aggregate data. If you need to transform data in ways that are not supported by the standard transformations, you can easily write a script for the Script transformation or code a custom transformation to address your needs. In this lesson you will enhance the basic package to sort the data and add a new column based on values from other columns to the dataset. In this scenario, one column contains null values, which present problems when concatenating values from existing columns. To work around this problem and generate the value for the new column, you will use a new Integration Services featureexpressions. The Integration Services expression language includes functions, operators, and type casts that you can use to build complex expressions. You will use an expression to concatenate the values from three columns and conditionally insert a space between columns, and then add the new value to the new column. Because a new column is added to the dataset, the ProspectiveCustomers table and the OLE DB destination must be modified to include this column. You will update both the SQL statement in the Execute SQL task that created the ProspectiveCustomers table, and the OLE DB destination that writes data to the table, to include this new column. You will also map the new column in the dataset to the new column in the table. In this lesson, you will copy and then enhance the basic created in Lesson 1. If you have not completed the previous lesson, you can also copy the completed package for Lesson 1 that is included with the tutorial.
Important
This tutorial requires the AdventureWorks2008R2 sample database. For more information about how to install a see Considerations for Installing SQL Server Samples and Sample Databases.
Lesson Tasks
This lesson contains the following tasks:
Step 1: Copying the Lesson 1 Basic Package Step 2: Updating the Execute SQL Task Step 3: Adding and Configuring the Sort Transformation Step 5: Modifying the OLE DB Destination Step 6: Testing the Lesson 2 Basic Package
In this task, you will create a copy of the package that you created in Lesson 1, named Basic Package Lesson 1.dtsx. If you did not complete Lesson 1, you can add the completed Lesson 1 package that is included with the tutorial to the project, and then copy it instead. You will use this new copy throughout the rest of Lesson 2.
2.
3. 4.
3. 4.
5.
In the Add Copy of Existing Package dialog box, in Package location, select File system. Click the browse () button, navigate to C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Tutorial\Creating a Basic Package\Completed Packages, select Basic Package Lesson 1.dtsx, and then click Open. Copy and paste the Basic Package Lesson 1 package as described in steps 3-8 in the previous procedure.
In this task, you will update the SQL statement in the Execute SQL task named Preparation SQL Task. The existing SQL statement was automatically generated from the options you specified when you stepped through the SQL Server Import and Export Wizard pages to create the lesson 1 package. This SQL statement creates the Query table in the AdventureWorks2008R2 database when the package is run. Later in this lesson, you will generate an additional column to the data that is extracted from the Excel spreadsheet, and you need to include a definition of that column in the SQL statement.
[MaritalStatus] nchar(1), [Gender] nchar(1) NOT NULL, [EmailAddress] nvarchar(50), [YearlyIncome] money, [TotalChildren] tinyint, [NumberChildrenAtHome] tinyint, [Education] nvarchar(50), [Occupation] nvarchar(50), [HouseOwnerFlag] bit, [NumberCarsOwned] tinyint, [AddressLine1] nvarchar(60), [AddressLine2] nvarchar(60), [City] nvarchar(30), [State] nchar(3), [ZIP] float, [Phone] nvarchar(50), [FullName] nvarchar (103) ) GO 5. 6. 7. Click OK. Click Parse Query. The SQL statement should parse successfully. Click OK.
In this task, you will add and configure a Sort transformation to your package. A Sort transformation is a data flow component that sorts data, and optionally applies rules to the comparison that the sort performs. The sort transformation can also be used to remove rows of data that have duplicate sort key values. The sort transformation will sort the data extracted from the Excel spreadsheet by state and by city.
4. 5. 6. 7.
In this task, you will add a Derived Column transformation to your package. A Derived Column transformation is a data flow component that creates new data values by using values in a dataset, constants, and variables, or by applying functions. You will use this transformation to add a new column and then populate the column with the evaluation results of an expression. The user interface for the Derived Column transformation includes the expression builder. This graphical tool makes it easy to quickly write complex expressions using drag and drop operations, and provides templates for functions, type casts, and operators as well as the input columns and variables. In the Derived Column transformation, you will create an expression that concatenates the values in the FirstName, MiddleInitial, and LastName columns in the dataset and then writes the result to a new column. Because the middle initial may be null, the expression will include special handling of this column. The new column, FullName, will be added to the transformation output.
You may optionally remove the brackets that enclose column names in the expression. The column names are regular identifiers, which do not need to be enclosed in brackets. Names that contain invalid characters, such as spaces, must be enclosed in brackets. If the expression has been typed incorrectly, the expression text will appear in red. 12. In the Derived Column box for the row you just created, select <add as new column>. 13. In the Derived Column Name box for the same row, type FullName. 14. If the Data Type box is not already set to Unicode string [DT_WSTR], select Unicode string [DT_WSTR] in the Data Type list. 15. Set the value of the Length box to 103 (the sum of the lengths of the FirstName, MiddleInitial, LastName columns, and two spaces.) 16. Click OK. 17. In the Properties window, verify that the LocaleID property is set to English (United States).
Earlier in lesson 2, you updated the SQL statement in the Execute SQL task, Preparation SQL Task, to include a definition of the FullName column in the Query table. In this task, you will modify the OLE DB destination, Destination - Query, to support the FullName column. You will also restore the column mappings in Destination - Query that are no longer valid because you added a Sort transformation to the data flow. The Sort transformation generates a new set of columns with different column identifiers, and you therefore need to remap the input columns and destination columns in Destination - Query.
You can clear the Include downstream invalid column references check box. In this package, there are no downstream data flow components and this option has no effect. 5. Click OK. 6. Right-click Destination - Query and click Show Advanced Editor. 7. In the Advanced Editor dialog box, click the Input and Output Properties tab, expand Destination Input, click External Columns, and then click Add Column. A new column named Column is added to the External Columns folder. 8. Click the new column. 9. In the right-hand pane, update the Name property to FullName, click the DataType property and select Unicode string [DT_WSTR] from the list. Update the Lengthproperty to 103. 10. Click the Columns Mappings tab, and scroll down to the row with FullName in the Destination Column list. Click <ignore> in the Input Column list of that row, and then click FullName in the list. 11. Verify that all input and output columns that have the same names are mapped. 12. Click OK.
In this lesson, you have done the following tasks: Updated the SQL statement in the Execute SQL task to include a definition for an additional column. Added and configured a Sort transformation to sort the dataset by state and then by city. Added a Derived Column transformation and configured it to use an expression to generate values for a new column. Modified the OLE DB destination to write the new column, FullName, to the ProspectiveCustomers table.
Important
The first time you run the package, the Drop table(s) Task will fail. This behavior is expected. The reason this ha and re-create the ProspectiveCustomers table; however, the first time that the package runs the table does not exi
Before you test the package, you should verify that the control and data flows in the Lesson 1 package contain the objects shown in the following diagrams. Control Flow
Data Flow
Also, the package should include the following two connection managers. One connects to the customers.xls Excel workbook file and the other one connects to the AdventureWorks2008R2 database.
3. 4. 5.
SELECT * FROM AdventureWorks2008R2.dbo.ProspectiveCustomers 6. On the toolbar, click Execute. The Results pane shows the dataset, including the new FullName column. You can verify that your expression formatted the column value correctly depending on whether the middle initial is null.