Export (0) Print
Expand All

Applying the Changes to the Destination

In the data flow of an Integration Services package that performs an incremental load of change data, the third and final task is to apply the changes to your destination. You will need one component to apply inserts, one to apply updates, and one to apply deletes.

NoteNote

The second task in designing the data flow of a package that performs an incremental load of change data is to separate inserts, updates, and deletes. For more information about this component, see Processing Inserts, Updates, and Deletes. For a description of the overall process for creating a package that performs an incremental load of change data, see Improving Incremental Loads with Change Data Capture.

To see complete, end-to-end samples that demonstrate the use of change data capture in packages, see the Integration Services samples on Codeplex.

To apply inserts, you use an OLE DB destination because the new rows do not require any special handling.

To process inserts by using an OLE DB Destination

  1. On the Data flow tab, add an OLE DB destination.

  2. Connect the output that contains inserts from the Conditional Split transformation to the OLE DB destination.

  3. In the OLE DB Destination Editor, on the Connection Manager page, select the following options:

    1. Select or create an OLE DB Connection Manager for the destination database.

    2. Select a Data access mode option, and then select the destination table or enter a SQL statement that contains the destination columns.

  4. On the Mappings page of the editor, map the appropriate columns from the change data to the destination table.

To apply updates, you use an OLE DB Command transformation. You use this transformation because you have to use a parameterized UPDATE statement to update one row at a time with the new column values.

NoteNote

You can also use destination components to apply updates. When using this approach, you use the destination components to save the rows to temporary tables that you create for this purpose. Then, you use Execute SQL tasks to perform bulk update and bulk delete operations against the destination from the temporary tables.

To process updates by using an OLE DB Command transformation

  1. On the Data flow tab, add an OLE DB Command transformation.

  2. Connect the output that contains updates from the Conditional Split transformation to the OLE DB Command transformation.

  3. In the Advanced Editor for OLE DB Command, on the Connection Manager tab, select or create an OLE DB Connection Manager for the destination database.

  4. In the Advanced Editor for OLE DB Command, on the Component Properties tab, for SqlCommand, enter a parameterized UPDATE statement.

    For example, an UPDATE statement for a Customer table might have the following syntax:

    update CDCSample.Customer
    set TerritoryID  = ?,
        CustomerType  = ?,
        rowguid  = ?,
        ModifiedDate  = ?
    where CustomerID = ?
    
    
  5. On the Column Mappings tab of the editor, map the appropriate columns from the change data to the parameters in the UPDATE statement.

To apply deletes, you use an OLE DB Command transformation. You use this transformation because you have to use a parameterized DELETE statement that deletes a single row at a time based on the column value that uniquely identifies the row.

NoteNote

You can also use destination components to apply deletes. When using this approach, you use the destination components to save the rows to temporary tables that you create for this purpose. Then, you use Execute SQL tasks to perform bulk update and bulk delete operations against the destination from the temporary tables.

To process deletes by using an OLE DB Command transformation

  1. On the Data flow tab, add an OLE DB Command transformation to the data flow.

  2. Connect the output that contains deletes from the Conditional Split transformation to the OLE DB Command transformation.

  3. Open the Advanced Editor to configure the transformation.

  4. In the Advanced Editor for OLE DB Command, on the Connection Manager tab, select or create an OLE DB Connection Manager for the destination database.

  5. In the Advanced Editor for OLE DB Command, on the Component Properties tab of the editor, for SqlCommand, enter a parameterized DELETE statement.

    For example, a DELETE statement for a Customer table might have the following syntax:

    delete from Customer where CustomerID = ?
    
    
  6. On the Column Mappings tab of the editor, map the appropriate column from the change data to the parameter in the DELETE statement.

You can optimize the processing of inserts and updates by combining certain change data capture options with the use of the Transact-SQL MERGE keyword. For more information about the MERGE keyword, see MERGE (Transact-SQL).

In the Transact-SQL statement that retrieves the change data, you can specify all with merge as the value of the row_filter_option parameter when you call the cdc.fn_cdc_get_net_changes_<capture_instance> function. This change data capture function operates more efficiently when it does not have to perform the extra processing that is required to distinguish inserts from updates. When you specify the all with merge parameter value, the __$operation value of the change data is 1 for deletes or 5 for changes that were caused by inserts or updates. For more information about the Transact-SQL function that is used to retrieve the change data, see Retrieving and Understanding the Change Data.After retrieving changes with the all with merge parameter value, you can apply deletes, and output the remaining rows to a temporary table or a staging table. Then, in a downstream Execute SQL Task, you can use a single MERGE statement to apply all the inserts or updates from the staging table to the destination.

Integration Services icon (small) Stay Up to Date with Integration Services

For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN or TechNet:

For automatic notification of these updates, subscribe to the RSS feeds available on the page.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft