Training
Certifications
Books
Special Offers
Community




 
MCSE Training Kit (Exam 70-228): Microsoft® SQL Server™ 2000 System Administration
Author Microsoft Corporation
Pages 720
Disk 1 Companion CD(s)
Level All Levels
Published 03/28/2001
ISBN 9780735612471
ISBN-10 0-7356-1247-1
Price(USD) $59.99
To see this book's discounted price, select a reseller below.
 

More Information

About the Book
Table of Contents
Sample Chapter
Index
Related Series
Related Books
About the Author

Support: Book & CD

Rate this book
Barnes Noble Amazon Quantum Books

 


Chapter 7: Populating a Database continued


Lesson 3: Transferring and Transforming Data with DTS Graphical Tools

DTS provides two graphical tools that you can use to create DTS packages that transfer and transform data. In this lesson, you will learn to use each of these. First, you will learn to use the DTS Import/Export Wizard to create simple transformations. Then, you will learn to use DTS Designer to create more complex transformations and workflows. You will also learn to save these packages in a variety of formats. Finally, you will learn about extending the functionality of DTS packages.


After this lesson, you will be able to

  • Use the DTS Import/Export Wizard to create a DTS package
  • Use DTS Designer to create a DTS package
  • Save DTS packages to a variety of formats
  • Describe additional functionality that can be added to DTS packages

Estimated lesson time: 60 minutes


Using the DTS Import/Export Wizard

The DTS Import/Export Wizard can be started from the Microsoft SQL Server program group on the Start menu and from within SQL Server Enterprise Manager. Within SQL Server Enterprise Manager, you can start this wizard by clicking the Tools menu and then pointing to Wizards, or by right-clicking the Data Transformation Services container in the console tree, pointing to All Tasks, and then clicking either Import Data or Export Data (both bring up the same wizard). The DTS Import/Export Wizard guides you through the steps to import or export data between many different formats.

The first step in this process is selecting the data source in the Choose A Data Source page. The default data source is the Microsoft OLE DB Provider for SQL Server. This data source is used to connect to an instance of SQL Server. Select the data-specific driver for the data storage format from which you want to copy data (such as a text file or an Oracle database) from the Data Source drop-down list. The remaining properties you will define on this page depend upon the data source selected. For example, if your data source is SQL Server, you provide the server name, authentication type, and database. See Figure 7.1.

Click to view graphic
Click to view graphic

Figure 7.1  Selecting the data source in the DTS Import/Export Wizard.

If you are using a different data source, other connection information is required. For example, if you are copying data from a text file, you must provide the filename on the Choose A Data Source page, followed by file format information (including fixed or delimited fields, file type, row and column delimiters, and text qualifiers), which you select on the the Select File Format page and the Specify Column Delimiter page. See Figures 7.2, 7.3, and 7.4.

Click to view graphic
Click to view graphic

Figure 7.2  Specifying a text file as the data source.

Click to view graphic
Click to view graphic

Figure 7.3  Selecting the file format, field type, and text qualifier.

Click to view graphic
Click to view graphic

Figure 7.4  Specifying the column delimiter.

The next step in this process is selecting the data destination in the Choose A Destination page. Again, the default data source is the Microsoft OLE DB Provider for SQL Server, for which you must provide a server name and connection information. You can select from a wide variety of data destinations. Both your data source and your data destination can be products other than SQL Server 2000. See Figure 7.5. For example, you could use DTS to copy data from Oracle to dBase. With SQL Server 2000, you can create a new database on the fly. If you create a new database, the physical location will be the same disk and folder as the master database. The only database properties you can choose in the Create Database dialog box are the name of the database and the sizes of the data file and the transaction log file. See Figure 7.6.

Click to view graphic
Click to view graphic

Figure 7.5  Selecting a destination for your data.

Click to view graphic
Click to view graphic

Figure 7.6  Specifying the name and properties of the new database.

After selecting your data source and your data destination, you specify or filter the data you will copy in the Specify Table Copy Or Query page. (This page will not appear if you are creating a new database.) Your choices will vary depending upon the data source and the data destination. If the data source is a database, you can perform a simple copy of data (unfiltered and unordered) by selecting the Copy Table(s) And View(s) From The Source Database option button, or you can perform a more complex copy requiring a Transact-SQL query (selecting only rows matching specified selection criteria and in a certain order) by selecting the Use A Query To Specify The Data To Transfer option button. In addition, if both the data source and destination are SQL Server 7.0 or SQL Server 2000 databases, you can copy database objects (such as stored procedures and logins) by selecting the Copy Objects And Data Between SQL Server Databases option button. See Figure 7.7.

Click to view graphic
Click to view graphic

Figure 7.7  Specifying the type of copy operation.

Copying Entire Tables and Views

If you choose to copy entire tables or views, you then select all or some of the tables or views for copying in the Select Source Tables And Views page. By default, the destination name for each table or view will be the name of the table or view being copied. You can create new table or view names, or select different existing tables or views. See Figure 7.8.

Click to view graphic
Click to view graphic

Figure 7.8  Selecting source tables and views.

If you perform no other action, the contents of each selected table or view will be copied without changes. If the destination table exists, by default, the data being copied will be appended to the existing data. If the destination table does not exist, the table will be created using the specified name. If you want to change these defaults, on the Select Source Tables And Views page, click the ellipsis in the Transform column for each table or view you want to transform. On the Column Mappings tab of the Column Mappings And Transformations dialog box, you can specify the mappings between source and destination columns, create a new destination table, edit the CREATE TABLE Transact-SQL statement (if a new table or view is being created), choose to delete or append rows in the destination table (if an existing table is detected), enable insert identity (if an identity column is detected), and change the data type (if a valid data conversion is available). See Figure 7.9.

Click to view graphic
Click to view graphic

Figure 7.9  Changing the column mappings and transformations.

You can also specify unique transformations using either VBScript or JScript (VBScript is the default) on the Transformations tab of the Column Mappings And Transformations dialog box. To transform data while it is being copied, edit the script in the test area to customize columns before copying them to the destination. See Figure 7.10. Although you can perform some customized transformations using the DTS Import/Export Wizard, DTS Designer is more appropriate for complex scripting through the use of ActiveX scripting.

Querying to Specify the Data

If you choose to use a query to specify the data to transfer, you can write your own Transact-SQL script in the space provided in the Type SQL Statement page, browse and import an existing script, or click the Query Builder button to graphically create a script using DTS Query Designer. DTS Query Designer is a graphical query-building tool. A Parse button is provided to test the syntax of your script. See Figure 7.11.

Click to view graphic
Click to view graphic

Figure 7.10  Specifying transformation options.

Click to view graphic
Click to view graphic

Figure 7.11  Creating a script using the Query Designer.

After you enter your Transact-SQL script and click Next, you can select and then preview your results by clicking the Preview button in the Select Source Tables And Views page (see Figure 7.8) to verify whether the query produces the results you intend. If you perform no other action, the results of the query are copied to a new table called Results. You can modify this name. You can also click the ellipsis in the Transform column in the Select Source Tables and Views page (see Figure 7.8) to modify the column mappings and specify custom transformations in a manner similar to that discussed earlier. See Figure 7.12.

Click to view graphic
Click to view graphic

Figure 7.12  Modifying the column mappings and transformations for your query.

Copying Objects and Data Between SQL Server Databases

If you choose to copy objects and data between SQL Server databases, you can specify which objects you want to transfer between SQL Server instances in the Select Objects To Copy page. You can only copy between SQL Server 7.0 instances or SQL Server 2000 instances or from a SQL Server 7.0 instance to a SQL Server 2000 instance (not from SQL Server 2000 to SQL Server 7.0). By default, destination objects are created for all objects being copied (all objects are copied by default), all corresponding destination objects are dropped before the new ones are created, and all dependent objects are included in the transfer of data. In addition, by default, all data is copied and all existing data on the destination is deleted. See Figure 7.13. You can limit the objects being copied (such as only certain tables or stored procedures, or no indexes).

Saving and Scheduling Packages

The final step in the DTS Import/Export Wizard for any of the types of transformations described so far is to choose to run the package immediately, or to choose to save or to schedule the package on the Save, Schedule, And Replicate Package page. See Figure 7.14. By default, the package will run immediately and will not be saved or scheduled. You can choose to schedule it to run at a later time as a job under the auspices of SQL Server Agent. Jobs and scheduling are covered in Chapter 13. You can also choose to save the package in any of the supported formats. Choosing between these formats is covered in Lesson 4.

Click to view graphic
Click to view graphic

Figure 7.13  Selecting objects to copy.

Click to view graphic
Click to view graphic

Figure 7.14  Choosing to save or schedule the package.

Practice: Transferring Tables and Data from the Northwind Database Using the DTS Import/Export Wizard

In this practice you transfer tables and data from the Northwind database to a new database using the DTS Import/Export Wizard. Then, you modify these tables and summarize data in the NorthwindReportData database.

To transfer tables and data from the Northwind Database using the DTS Import/Export Wizard

  1. Ensure that you are logged on to the SelfPacedSQL.MSFT domain server as Administrator.
  2. Click Start, point to Programs, point to Microsoft SQL Server, and then click Import And Export Data.
  3. The DTS Import/Export Wizard appears.

  4. Click Next.
  5. The Choose A Data Source page appears.

  6. In the Data Source drop-down list, verify that the selected data source is Microsoft OLE DB Provider for SQL Server.
  7. In the Server drop-down list, select SelfPacedCPU\MyNamedInstance.
  8. Verify that the Use Windows Authentication option button is selected.
  9. In the Database drop-down list, select Northwind and then click Next.
  10. The Choose A Destination page appears.

  11. In the Destination drop-down list, verify that the selected data destination is Microsoft OLE DB Provider for SQL Server.
  12. In the Server drop-down list, select SelfPacedCPU.
  13. Verify that the Use Windows Authentication option button is selected.
  14. In the Database drop-down list, select <New>.
  15. The Create Database dialog box appears.

  16. In the Name text box, type NorthwindReportData and then click OK.
  17. The Choose A Destination page reappears displaying the new database.

  18. Click Next.
  19. The Specify Table Copy Or Query page appears.

  20. Verify that the Copy Table(s) And View(s) From The Source Database option button is selected and then click Next.
  21. The Select Source Tables And Views page appears.

  22. Click the Select All button.
  23. Notice that the name for each destination table is automatically filled in using the same name as the source table.

  24. Click Next.
  25. The Save, Schedule, And Replicate Package page appears.

  26. Verify that the Run Immediately check box is selected.
  27. Select the Save DTS Package check box, verify that the SQL Server option button is selected, and then click Next.
  28. The Save DTS Package page appears.

  29. In the Name text box, type NorthwindTableCopy and then click Next.
  30. The Completing The DTS Import/Export Wizard page appears.

  31. Click the Finish button.
  32. The Executing Package dialog box appears displaying the status of the package execution, showing each step. When the package finishes executing, a DTS Import/Export Wizard message box appears stating that 29 tables were successfully copied from Microsoft SQL Server to Microsoft SQL Server.

  33. Click OK.
  34. In the Executing Package page, briefly review the successfully completed steps and then click the Done button.
  35. In the SQL Server Enterprise Manager console tree, expand the default instance and then expand Databases.
  36. Notice that the NorthwindReportData database appears (you might need to press the F5 key to refresh the console tree).

To modify tables and summarize data in the NorthwindReportData database using the DTS Import/Export Wizard

  1. Right-click NorthwindReportData, point to All Tasks, and then click Import Data.
  2. The DTS Import/Export Wizard appears.

  3. Click Next.
  4. The Choose A Data Source page appears.

  5. In the Data Source drop-down list, verify that the selected data source is Microsoft OLE DB Provider for SQL Server.
  6. In the Server drop-down list, select SelfPacedCPU.
  7. Verify that the Use Windows Authentication option button is selected.
  8. In the Database drop-down list, select Northwind and then click Next.
  9. The Choose A Destination page appears.

  10. In the Destination drop-down list, verify that the selected data destination is Microsoft OLE DB Provider for SQL Server.
  11. In the Server drop-down list, verify that SelfPacedCPU is selected.
  12. Verify that the Use Windows Authentication option button is selected.
  13. In the Database drop-down list, verify that NorthwindReportData is selected and then click Next.
  14. The Specify Table Copy Or Query page appears.

  15. Select the Use A Query To Specify The Data To Transfer option button and then click Next.
  16. The Type SQL Statement page appears.

  17. Click the Browse button.
  18. The Open dialog box appears.

  19. Using the Look In drop-down list, browse to C:\SelfPacedSQL\CH_7 and open the Query.sql script.
  20. The contents of the Query.sql script appear in the Query Statement box.

  21. Click Next.
  22. The Select Source Tables And Views page appears.

  23. Click the Results cell in the Destination column and type TotalValue.
  24. Make sure you type TotalValue as a single word with no spaces.

  25. Click the Preview button.
  26. The View Data dialog box appears displaying the results of the query.

  27. Click OK.
  28. The Select Source Tables And Views page reappears.

  29. Click the ellipsis in the Transform column.
  30. The Column Mappings And Transformations dialog box appears.

  31. Click the Edit SQL button.
  32. The Create Table SQL Statement dialog box appears.

  33. Review the Transact-SQL statement.
  34. Notice that the TotalValue column allows nulls.

  35. Click OK to close the Create Table SQL Statement dialog box.
  36. The Column Mappings And Transformations dialog box reappears.

  37. In the Mappings grid, clear the Nullable check box for the TotalValue row.
  38. Click the Edit SQL button to review the Transact-SQL statement.
  39. The Create Table SQL Statement dialog box appears. Notice that the TotalValue column no longer allows nulls.

  40. Click OK to close the Create Table SQL Statement dialog box.
  41. Click OK to close the Column Mappings And Transformations dialog box.
  42. The Select Source Tables And Views page reappears.

  43. Click Next.
  44. The Save, Schedule, And Replicate Package page appears.

  45. Verify that the Run Immediately button is selected.
  46. Select the Save DTS Package check box.
  47. Select the SQL Server Meta Data Services option button, and then click Next.
  48. The Save DTS Package page appears.

  49. In the Name text box, type NorthwindTableTransform and then click Next.
  50. The Completing The DTS Import/Export Wizard page appears.

  51. Click the Finish button.
  52. The Executing Package dialog box appears displaying the status of the package execution, showing each step. When the package finishes executing, a DTS Import/Export Wizard message box appears stating that one table was successfully copied from Microsoft SQL Server to Microsoft SQL Server.

  53. Click OK.
  54. Briefly review the successfully completed steps in the Executing Package dialog box and then click the Done button.
  55. In the SQL Server Enterprise Manager console tree, expand the default instance, expand Databases, expand NorthwindReportData, and then click Tables.
  56. In the details pane, right-click TotalValue, point to Open Table, and then click Return All Rows.
  57. The Data In Table ‘TotalValue’ In ‘NorthwindReportData’ On ‘SelfPacedCPU’ window appears displaying the contents of this newly created and populated table.

  58. Close the Data In Table ‘TotalValue’ In ‘NorthwindReportData’ On ‘SelfPacedCPU’ dialog box.
  59. Do not close SQL Server Enterprise Manager.

Using DTS Designer

To create a new package using DTS Designer, in the SQL Server Enterprise Manager console tree, right-click Data Transformation Services and then click New Package. The method of opening an existing package within the Data Transformation Services container depends on how the DTS package was stored. If the DTS package was saved as a structured storage file, right-click Data Transformation Services, and then click Open Package to open the file from disk. If the DTS package was saved to SQL Server, click the Local Packages container in the console tree (in the Data Services container) and then double-click the DTS package in the details pane. If the DTS package was saved to SQL Server Meta Data Services, click the Meta Data Services container in the console tree (in the Data Services container) and then double-click the DTS package in the details pane.

DTS Designer allows you to graphically create connections to data sources and destinations, configure DTS tasks, perform DTS transformations, and specify precedence constraints. You use the drag-and-drop method and you complete the dialog boxes for objects in order to create DTS packages within the design sheet. Figure 7.15 displays the user interface for DTS Designer.

Click to view graphic
Click to view graphic

Figure 7.15  The DTS Designer user interface.

When creating a DTS package using DTS Designer, the first step is to select a data source. You can either drag a data source object from the Connection toolbar to the design sheet or select a data source from the Connection menu item. The Connection Properties dialog box that appears varies based on the data source selected. Complete the dialog box to configure the data source. This dialog box is similar to the dialog box displayed by the DTS Import/Export Wizard. Figure 7.16 displays the dialog box for a connection to SQL Server using the Microsoft OLE DB Provider for SQL Server.

Click to view graphic
Click to view graphic

Figure 7.16  The Connection dialog box.

The next step is to select and configure a data destination in the same manner as described above. Figure 7.17 displays a design sheet consisting of three data sources: two connections to Microsoft OLE DB Provider for SQL Server and one connection to a Text File (Source).

Click to view graphic
Click to view graphic

Figure 7.17  Configuring a data destination.


NOTE:
A connection to a text file specifies that the text file is either a data source or a data connection.

Next, you need to define the tasks that you want to occur using either the Task menu or the Task toolbar. If you select the Transform Data task, you are prompted to select the data source and the data destination. If you select any other task, a dialog box will appear to prompt you to configure the properties of the task (such as configuring the Execute SQL Task to create a table using an existing data connection). If you select the Transform Data task, a dark gray arrow appears pointing from the data source to the data destination. If you select any other task, it simply appears in the design sheet as an icon. Figure 7.18 displays two Transform Data tasks and an Execute SQL task that creates a table (in addition to three data connections).

To edit and customize a Data Transformation task, double-click the dark gray arrow between the data source and the data destination to open the dialog box for that task. On the Source tab, if the data source is a database, you can filter the data being copied by selecting specific tables or views or by using a Transact-SQL query. Figure 7.19 displays a Transact-SQL query being used to filter the data being imported.

Click to view graphic
Click to view graphic

Figure 7.18   Partial DTS Package without workflow control.

Click to view graphic
Click to view graphic

Figure 7.19  Using a query to filter the imported data.

On the Destination tab, you can define information about the data being imported (such as column definitions). Your choices will vary depending on the data destination. If the data destination is a database, you can create and define a new table or select an existing table for each table being imported.

On the Transformations tab, you can configure custom transformations. By default, the source columns are copied to the destination columns without modification. If you want to modify column data between the data source and the data destination, select the column you want to have modified either in the Name drop-down list or by clicking the arrow between the source and the destination (the arrow between the source and the destination for the selected column will appear bold). Next, click the New button or the Edit button to create a new transformation or modify an existing transformation (double-clicking the black arrow modifies the existing transformation). If you click the New button, you can choose the type of transformation you want from a list of available transformations in the Create New Transformation dialog box. See Figure 7.20.

Click to view graphic
Click to view graphic

Figure 7.20  Creating a new transformation.

If you select ActiveX Script from the Create New Transformation dialog box, you can create a new transformation script to perform more complex transformations. See Figure 7.21.

On the Lookups tab, you can define a lookup query. A lookup query requires a data connection to run queries and stored procedures against, in addition to a data source and data destination. Use a lookup query to look up tabular information, perform parallel updates on multiple database systems, validate input before loading, invoke stored procedures in response to input conditions, and use global variable values as query parameters.

On the Options tab, you can define a number of additional properties for the transformation. You can define one or more exception files to be used for recording exception records during package execution. This file can be on either a local drive or a network drive. The file can be written in a SQL Server 7.0 format for backward compatibility. You can split source and destination errors into separate files. You can also define a maximum number of errors allowed before the execution of the package will cease. Finally, you can also define specific execution properties when the destination connection is the Microsoft OLE DB Provider for SQL Server. These properties include specifying high-speed bulk-copy processing, constraint checking during package execution, lock type, batch size, and identity insert properties.

Click to view graphic
Click to view graphic

Figure 7.21  Creating a new transformation script.

Once you have configured the Data Transformation task and any other DTS tasks your DTS package will perform, you must configure precedence constraints. In our simple example, we have data from two separate data sources being copied to a data destination. We also have a Create Table task. You use precedence constraints to determine the order of execution of each task. To establish workflow precedence, select two or more tasks in the order the tasks will execute, and then select the type of workflow from the Workflow menu. For example, if the Create Table task must execute before the data copy to the data destination, select the On Success precedence constraint from the Workflow menu. See Figure 7.22.

You could create a Send Mail task and configure an On Failure precedence constraint between the Create Table task and the Send Mail task. This would send an e-mail notification to an administrator if the Create Table task failed. When you are using fully automated and scheduled DTS packages to perform database operations, failure notification is essential.

Click to view graphic
Click to view graphic

Figure 7.22  Selecting the On Success precedence constraint.

Practice: Creating a Data Transfer and Transform Package Using DTS Designer

In this practice you create a data transfer and transform package using DTS Designer.

To create a data transfer and transform package using DTS Designer

  1. Ensure that you are logged on to the SelfPacedSQL.MSFT domain server as Administrator.
  2. In the SQL Server Enterprise Manager console tree, expand the Microsoft SQL Servers container, expand the SQL Server Group container, and then expand the default instance.
  3. Right-click Data Transformation Services and then click New Package.
  4. DTS Designer appears.

  5. On the Connection menu, click Text File (Source).
  6. The Connection Properties dialog box appears.

  7. In the New Connection text box, type New Products.
  8. In the File Name text box, type C:\SelfPacedSQL\CH_7\NewData.inc and then click OK.
  9. The Text Files Properties dialog box appears displaying the Select File Format page.

  10. Verify that the Delimited Columns Are Separated By Character(s) option button is selected and then click Next.
  11. The Specify Column Delimiter page appears.

  12. Verify that the Comma option button is selected and then click the Finish button.
  13. The Connection Properties dialog box reappears.

  14. Click OK.
  15. The New Products icon appears on the design sheet.

  16. On the Connection menu, click Microsoft OLE DB Provider for SQL Server.
  17. The Connection Properties dialog box appears.

  18. In the New Connection text box, type Northwind Report Data.
  19. In the Server drop-down list, verify that SelfPacedCPU is selected.
  20. In the Database drop-down list, select NorthwindReportData and then click OK.
  21. The New Products and Northwind Report Data icons both appear on the design sheet.

  22. On the Task menu, click Transform Data Task.
  23. Your mouse pointer changes and displays the words Select Source Connection and has an arrow attached to it.

  24. Click the New Products icon.
  25. Your mouse pointer changes and displays the words Select Destination Connection and has an arrow attached to it.

  26. Click the Northwind Report Data icon.
  27. A dark gray arrow appears pointing from the New Products icon to the Northwind Report Data icon.

  28. Double-click the dark gray arrow.
  29. The Transform Data Task Properties dialog box appears with the Source tab selected.

  30. In the Description text box, type Adding New Products.
  31. Click the Destination tab.
  32. Click the Create button to create a new table into which to insert data.
  33. The Create Destination Table dialog box appears displaying a CREATE TABLE statement.

  34. Delete the entire CREATE TABLE statement.
  35. Using Notepad, open the NewProducts.sql file in C:\SelfPacedSQL\CH_7.
  36. Copy the contents of this file and paste the contents into the SQL Statement box, and then click OK.
  37. The Transform Data Task Properties dialog box reappears.

  38. Click the Transformations tab.
  39. Notice the default mappings of source columns to destination columns. In particular, notice that there are more columns in the destination than there are in the source. The reason is that we have added a column entitled TotalValue, which will be an aggregated column from two existing columns. Also notice that columns 8–10 are incorrectly mapped because of the addition of this new column.

  40. Right-click the mapping arrow between Col010 and ReorderLevel and then click the Edit button.
  41. The Transformation Options dialog box appears with the General tab selected.

  42. Click the Destination Columns tab.
  43. In the Selected Columns list, click the < button to remove ReorderLevel.
  44. From the Available Columns list, click Discontinued, click the > button and then click OK.
  45. Notice that the mapping has now changed for Col010 to Discontinued.

  46. Right-click the mapping arrow between Col009 and UnitsOnOrder and then click the Edit button.
  47. The Transformation Options dialog box appears with the General tab selected.

  48. Click the Destination Columns tab.
  49. In the Selected Columns list, click the < button to remove UnitsOnOrder.
  50. From the Available Columns list, click ReorderLevel, click the > button and then click OK.
  51. Notice that the mapping has now changed for Col009 to ReorderLevel.

  52. Right-click the mapping arrow between Col008 and TotalValue and then click the Edit button.
  53. The Transformation Options dialog box appears with the General tab selected.

  54. Click the Destination Columns tab.
  55. In the Selected Columns list, click the < button to remove TotalValue.
  56. From the Available Columns list, click UnitsOnOrder, click the > button and then click OK.
  57. Notice that the mapping has now changed for Col008 to UnitsOnOrder.

  58. In the Source column, click Col006, and then press Ctrl and click Col007.
  59. Notice that both Col006 and Col007 are selected.

  60. In the Destination column, click TotalValue.
  61. Click the New button.
  62. The Create New Transformation dialog box appears.

  63. Click ActiveX Script and then click OK.
  64. The Transformation Options dialog box appears with the General tab selected.

  65. Click the Properties button.
  66. The ActiveX Script Transformation Properties dialog box appears.

  67. Modify the line of code that reads
  68. DTSDestination("TotalValue")=DTSSource("Col006") 

    to read

    DTSDestination("TotalValue")=DTSSource("Col006")*DTSSource("Col007")

  69. Click the Parse button.
  70. A DTS Designer message box appears stating that the ActiveX script was successfully parsed.

  71. Click OK.
  72. Click the Test button.
  73. A Testing Transformation dialog box appears to test the Transformation and a Package Execution Results message box appears stating that the package was successfully executed.

  74. Click OK.
  75. Click the Done button in the Testing Transformation dialog box.
  76. Click OK in the ActiveX Script Transformation Properties dialog box.
  77. The Transformation Options dialog box reappears.

  78. Click OK in the Transformation Options dialog box.
  79. Notice that the mappings now show Col006 and Col007 combined and being mapped to TotalValue.

  80. Click OK in the Transform Data Task Properties dialog box.
  81. On the Task menu, click Execute SQL Task.
  82. The Execute SQL Task Properties dialog box appears.

  83. In the Description text box, type Drop Table.
  84. In the Existing Connection drop-down list, click Northwind Report Data.
  85. In the SQL Statement box, type DROP TABLE NewProducts and then click OK.
  86. The Drop Table task icon appears on the design sheet.

  87. On the Task menu, click Execute SQL Task.
  88. The Execute SQL Task Properties dialog box appears.

  89. In the Description text box, type Create Table.
  90. In the Existing Connection drop-down list, click Northwind Report Data.
  91. Click the Browse button.
  92. The Select File dialog box appears.

  93. Using the Look In drop-down list, browse to C:\SelfPacedSQL\CH_7 and then open the NewProducts.sql script.
  94. The saved CREATE TABLE statement appears in the SQL statement box.

  95. Click OK.
  96. The Create Table task icon appears on the design sheet.

  97. On the Task menu, click Execute SQL Task.
  98. The Execute SQL Task Properties dialog box appears.

  99. In the Description text box, type Backup Northwind Report Data.
  100. In the Existing Connection drop-down list, click Northwind Report Data.
  101. Click the Browse button and then open the BackupNorthwindReportData.sql script in C:\SelfPacedSQL\CH_7.
  102. The saved BACKUP DATABASE statement appears in the SQL statement box. Change the drive path in this script if you are not using the C drive for your SQL Server 2000 program and data files.

  103. Click OK.
  104. The Backup Northwind Report Data task icon appears on the design sheet.

  105. Click the Drop Table task icon and then press Ctrl and click the Create Table task.
  106. Notice that both task icons are selected.

  107. On the Workflow menu, click On Completion.
  108. A blue-and-white striped arrow appears between the Drop Table and the Create Table task icons. The Create Table task will execute whenever the Drop Table task completes, regardless of the success of the Drop Table task. If the NewProducts table does not exist, the Drop Table task will fail and the Create Table task will create the table.

  109. Click the Create Table task icon and then press Ctrl and click the New Products icon.
  110. On the Workflow menu, click On Success.
  111. A green-and-white striped arrow appears between the Create Table task and the New Products to Northwind Report Data task icons. The New Products to Northwind Report Data task will only execute when and if the Create Table task creates the NewProducts table.

  112. Click the Northwind Report Data icon and then press Ctrl and click the Backup Northwind Report Data icon.
  113. On the Workflow menu, click On Success.
  114. A green-and-white striped arrow appears between the New Products to Northwind Report Data task icon and the Backup Northwind Report Data task icon. The Backup Northwind Report Data task will only execute when and if the New Products to Northwind Report Data task completes successfully.

  115. On the Package menu, click Save.
  116. The Save DTS Package dialog box appears.

  117. In the Package Name text box, type Lesson 2 and then click OK.
  118. On the toolbar, click the Execute button.
  119. The Executing DTS Package: Lesson 2 dialog box appears displaying the progress of the execution of the DTS package. When the DTS package is complete, a Package Execution Results message box appears stating that the execution of the package was successful.

  120. Click OK and then click the Done button.
  121. Close DTS Package: Lesson 2 by clicking the Close button for the DTS Designer window.
  122. In the SQL Server Enterprise Manager console tree, expand the Microsoft SQL Servers container, expand the SQL Server Group container, expand the default instance, expand Databases, expand NorthwindReportData, and then click Tables.
  123. In the details pane, right-click NewProducts, point to Open Table, and then click Return All Rows. You might need to press F5 to refresh the display.
  124. The Data In Table ‘NewProducts’ In ‘NorthwindReportData’ On ‘SelfPacedCPU’ dialog box appears. Notice that the new table is populated and the aggregated column, TotalValue, exists.

  125. Close the Data In Table ‘NewProducts’ In ‘NorthwindReportData’ On ‘SelfPacedCPU’ window.
  126. Do not close SQL Server Enterprise Manager.

Extending DTS Package Functionality

You can extend the capabilities of your DTS packages in a variety of ways. It is beyond the scope of this book to cover all of the ways you can incorporate the plethora and complexity of DTS tasks into DTS packages. However, the following extended functionality deserves specific mention.

Transaction Support

DTS packages support distributed transactions using functions provided by Microsoft Distributed Transaction Coordinator (DTC). To obtain this functionality, DTC must be running on the computer executing the DTS package. Distributed transactions are used to ensure that DTS tasks within a package that occur in parallel are all committed successfully or none are committed. This is particularly useful when a DTS package spans multiple database servers or when multiple DTS packages run under the control of a single DTS package.

Message Queue Task

The Message Queue task allows you to use Message Queuing to send and receive messages between DTS packages. These messages can be text, files, or global variables and their values. Message queuing allows these messages to be sent when the destination DTS package is unavailable (such as when various laptop computers are disconnected). When a destination DTS package becomes available, the originating DTS package continues until complete. Other available options include sending data files to the computer responsible for processing them, distributing files throughout the enterprise, and splitting a large job into several component parts and then parceling them out to different computers in the
network.


NOTE:
There are two types of message queuing, transactional and non-transactional. Using transactional message queuing provides assurance that each message is delivered only once.

To use the Message Queue task, you must install Message Queuing server software on your network and Message Queuing client software on the computer running the Message Queue task. For Windows 2000, you install Message Queuing server software on a Windows 2000 domain controller running Active Directory. Thereafter, you can install Message Queuing client software on your computer. For Windows NT, you install MSMQ from the Windows NT 4.0 Option Pack.

Send Mail Task

The Send Mail task allows a DTS package to notify an administrator about its progress (such as the success or failure of a database backup). The Send Mail task can also send attachments, which can consist of dynamically updated files. The Send Mail task requires the installation of Messaging Application Programming Interface (MAPI) on the local computer with a valid user profile for the domain user account used by the SQL Server service.

Programming Templates

SQL Server 2000 also ships with a wide variety of programming samples for Visual C++ and Visual Basic. These samples are located on the SQL Server 2000 compact disk in the \DevTools\Samples\Dts folder in a self-extracting zip file and can be installed during a Custom setup (by default to the C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\Dts folder).

Lesson Summary

You can use the DTS Import/Export Wizard to copy and transform data and database objects. It is most useful for copying data and database objects between one data source and one data destination with minimal transformations. Use DTS Designer for more complex transformation packages. DTS Designer allows you to create packages to and from multiple data sources and destinations using workflow logic, message queuing, and transaction control. You can also use Visual Basic and Visual C++ to extend the complexity and more finely control the workflow logic of DTS packages.


Previous   |  Table of Contents   |   Next




Top of Page


Last Updated: Saturday, July 7, 2001