Data was not updating rows that contained existing primary key

SPorter 0 Reputation points
2025-11-05T15:51:29.65+00:00

Problem: 

Data was not updating rows that contained existing primary key.

Solution: 

Go through and run where row exists update if not insert.

Conflict:

This increases row count which thus increases total files: 100+ added to each month.

Possible Resolution:

Is it possible to utilize azure data factory to create a procedure where data can update/ insert rows? If so how?

SQL Server on Azure Virtual Machines
{count} votes

2 answers

Sort by: Most helpful
  1. Abhisek Mishra 1,020 Reputation points Microsoft External Staff Moderator
    2025-11-05T17:38:49.12+00:00

    Hi SPorter,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Yes, Azure Data Factory (ADF) can be used to handle this kind of data update/insert scenario by implementing an Upsert operation. You can use a stored procedure to handle the logic directly in the database. A stored procedure can perform an upsert operation using SQL’s MERGE statement. Edit the below Merge statement as per your need and put it in a SP.

    MERGE INTO TargetTable AS target

    USING SourceTable AS source

    ON target.PrimaryKey = source.PrimaryKey

    WHEN MATCHED THEN

    UPDATE SET

    target.Column1 = source.Column1,

    target.Column2 = source.Column2

    -- Include all the columns you want to update

    WHEN NOT MATCHED THEN

    INSERT (PrimaryKey, Column1, Column2)

    VALUES (source.PrimaryKey, source.Column1, source.Column2);

    You can call this stored procedure from an Azure Data Factory pipeline using a Stored Procedure Activity.

    Here's how you can call a Stored Procedure in ADF:

    • Create the Stored Procedure: Implement the MERGE logic in your SQL database as described above.
    • Call the Stored Procedure: In ADF, create a pipeline and add a Stored Procedure activity. Connect this activity to your SQL Database Linked Service. Set the procedure name and provide necessary parameters (if any).
    • Debug/Trigger the pipeline.

    I hope this information is helpful! If you still have questions or you come across issues, please let us know what is needed in the comments so this question can be answered.

    1 person found this answer helpful.
    0 comments No comments

  2. SPorter 0 Reputation points
    2025-11-07T18:14:15.7366667+00:00

    I have over 150 of the attached files. how do i run this quickly?

    image.png


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.