I want to copy an Azure SQL DB table exactly from a source DB to a destination DB. I currently have a "Copy data" activity that works great for upserting the data. But I also want to delete any records from the destination that do not exist in the source.
Truncating and recreating the destination table is not an option (lots of FKs). The only workaround I can think of is to create a staging table in the destination DB, dump all the source records to it, delete from destination if not exists in staging, and then drop the staging table. Is there a more elegant way of doing this? I’m surprised this isn’t just a checkbox somewhere in the Copy data activity!
2
Answers
below would be the best way with a quick performance :
unfortunately that is the way and there is no aspect of delete which is not present in source but in sink with upsert option because:
If you want to delete the records from sink which are not in source, you can follow below options:
sink
), you may need to load the previous source data into a temp table in the sink database, write a stored procedure to remove and upsert the data fromtemp
tosink
and call it from stored procedure activity after first copy activity that copies data from source to temp table.