Focal Point
[SOLVED] Update in an Auto-Increment Key Table

This topic can be found at:

July 09, 2019, 04:19 PM
[SOLVED] Update in an Auto-Increment Key Table
I have an auto-increment table that I'd like to write to in an insert/update fashion.

I have a Data Migrator flow that left-outer-joins the destination table to the source table, so that I can capture the ID of the destination table. I

I pass all my fields from the source table across, and I'm sending the ID field from the destination table as well, which is either an integer (on a match in the join) or a null (on no match in the join).

I can't figure out how to make this run as an insert/update flow. How do I get the database to either a) update the existing record when the keys match; or b) insert when there is no key?

If I try to assign the ID SQL*Server throws and error.* If I don't assign the ID I get duplicate inserts of the same information.


This message has been edited. Last edited by: FP Mod Chuck,

July 11, 2019, 08:56 AM
You can't a assign a value to a column in MS SQL Server described as autoincrement. Not even a value of NULL, which in this case is not the same thing as not assigning a value.

If there is some other column(s) in your target table that uniquely identify the row you could use the Slowly Changing Dimension support to identify that column(s) as the logical key(s), the autoincrement column as the surrogate key, and the other columns as Type I.
July 11, 2019, 10:44 AM
If you could point me to an example I would appreciate it.

July 11, 2019, 04:04 PM
In the DataMigrator Users Guide see the section "Generating a Surrogate Key Using Slowly Changing Dimensions" and the section "SCD Type." For your purpose ignore the "Type II" and change flags.

Alternatively, create the DataMigrator tutorials for Star Schema and look at any of the dimension tables.