Skip to main content
Question

Challenging issue with database keys

  • September 30, 2019
  • 4 replies
  • 8 views

torbjornd
Contributor
Forum|alt.badge.img+4

Hi. I'm working on a workbench for migration of some data from one datamodel (MS Access) to another (MS SQL Server). One of the original tables contains information about contracts and contains the following fields:

contractid - companyid - signedDate - expirationDate - revisedid - revisedDate

When one of the contracts (A) has expired and has been revised, a new contract (B) has been added to the table and the field revisedid in the former row (A) is updated to contain the contractid to the latter one (B).

My problem is how to add this in the new datamodel. The corresponding table in the new datamodel has a identity field as primary key (ConsessionID), and the table does not contain any reference to the old contractid. I've added a featurewriter-transformer to write the new row, and I need to update the rows with the new contractid for revised contracts. What's the best way to accomplish this? My first (and best?) guess is to use a featurereader after the featurewriter, to get the new id's and then use FeatureJoiner to join the rows to know which rows to update.

Do you understand my problem and have any suggestions?

 

Regards, Torbjørn

4 replies

david_r
Evangelist
  • October 1, 2019

In 99% of such cases I would only consider doing something like this with a SQLExecutor using a single transaction block.

The issue with any other solution is what would happen if e.g. the workspace or anything else fails when only half of the update has been made. The data would be in an unknown state and could possibly create serious problems further down the line. By using a database transaction you're guaranteed that either the whole update goes through, or nothing at all.

 


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • October 1, 2019

I think for me there are two things I don't understand:

  1. Are you dropping the SQL Server table each time (so you migrate all of the Access table every time) or are you just doing a change-only update (so you migrate just changed records)?
  2. If you just migrate changed records, how do you know which ConcessionID was the old contract? Without contractid I don't see how you can ever tell which was the old contract.

mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • October 1, 2019

I mean, somehow you need a link between the old contractid and the new ConcessionID. Otherwise I don't see how you can go back to an old record and update it. Maybe one solution is to have a third table to act as a lookup. It has contractid and ConcessionID in it. So whenever you write a new record to SQL Server, you write contractid and ConcessionID to the lookup table. Now you have a means to make the join that you propose. Or rather, to retrieve the new ConcessionID and update it (maybe a writer with a Where clause, or maybe using SQL as David suggests).


torbjornd
Contributor
Forum|alt.badge.img+4
  • Author
  • Contributor
  • October 8, 2019

Thank you for the suggestions. I got this to work by using an sqlexecutor to get the current identity-value from the consession-table and a counter for creating the next identity values. Then I used a featurejoiner to join the appropriate records, before writing to the table using insert into identity column.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings