The problem is after each row is inserted I need to store the identity and update again it in the source. How is it possible in ADF, in ssms we can use identity_insert?
in first database, i have a table
ID1, name, ID2
1,'a',null
2,'b',null
in 2nd databse, table is
ID2, name
1,'a'
So, I need to update ID2 in first database after inserting from 1st database table to 2nd database table
2
Answers
Showcase of the full pipeline, as well as better explanation would be useful. Are you using storedprocs here to modify the databases?
Also, if you want changes to be updated every single time the table in the first database is updated, you can use CDC (Change data capture).
If your source and sink databases are same, then using copy activity pre copy script, you can get the desired result.
But you mentioned the source and sink are two different databases.
I could able to achieve your requirement as below.
NOTE: This approach only works for inserting records.
This is my source table with identity column ID1:
My target table with Identity column ID2:
First, I have taken source table ID1 column first value using lookup activity query
select TOP (1) ID1 from [dbo].[mysource]
.After the copy activity from source table to target table I have generated an array using range of values from ID1(1st row value) to number of records copied in copy activity(till last row ID1). I have used below dynamic content for it.
@range(activity('Source First ID').output.value[0].ID1,activity('Copy data1').output.rowsCopied)
Then I have taken another lookup query
select IDENT_CURRENT('mytarget2') as ID2;
to target table to get the current identity(last inserted ID2). I have used copy activity rows copied and this lookup output to generate target ID2 array using below dynamic content.Now, I am going to use the above arrays to update source table ID2 using script activity inside a ForEach. For iterating two arrays at a time inside a For Each I have generated an index array with
@range(0, activity('Copy data1').output.rowsCopied)
.Give this index array to ForEach activity and inside the ForEach use a script activity for source database with following dynamic content.
This is my Pipeline flow:
My Pipeline JSON:
Target table after Pipeline execution:
Source table with updated ID2 values after Pipeline execution: