Skip to content

Commit d17414b

Browse files
committed
Update connector-azure-sql-database.md
1 parent d96f74d commit d17414b

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

articles/data-factory/connector-azure-sql-database.md

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -686,35 +686,7 @@ Appending data is the default behavior of this Azure SQL Database sink connector
686686
687687
### Upsert data
688688
689-
**Option 1:** When you have a large amount of data to copy, you can bulk load all records into a staging table by using the copy activity, then run a stored procedure activity to apply a [MERGE](/sql/t-sql/statements/merge-transact-sql) or INSERT/UPDATE statement in one shot.
690-
691-
Copy activity currently doesn't natively support loading data into a database temporary table. There is an advanced way to set it up with a combination of multiple activities, refer to [Optimize Azure SQL Database Bulk Upsert scenarios](https://github.com/scoriani/azuresqlbulkupsert). Below shows a sample of using a permanent table as staging.
692-
693-
As an example, you can create a pipeline with a **Copy activity** chained with a **Stored Procedure activity**. The former copies data from your source store into an Azure SQL Database staging table, for example, **UpsertStagingTable**, as the table name in the dataset. Then the latter invokes a stored procedure to merge source data from the staging table into the target table and clean up the staging table.
694-
695-
:::image type="content" source="./media/connector-azure-sql-database/azure-sql-database-upsert.png" alt-text="Upsert":::
696-
697-
In your database, define a stored procedure with MERGE logic, like the following example, which is pointed to from the previous stored procedure activity. Assume that the target is the **Marketing** table with three columns: **ProfileID**, **State**, and **Category**. Do the upsert based on the **ProfileID** column.
698-
699-
```sql
700-
CREATE PROCEDURE [dbo].[spMergeData]
701-
AS
702-
BEGIN
703-
MERGE TargetTable AS target
704-
USING UpsertStagingTable AS source
705-
ON (target.[ProfileID] = source.[ProfileID])
706-
WHEN MATCHED THEN
707-
UPDATE SET State = source.State
708-
WHEN NOT matched THEN
709-
INSERT ([ProfileID], [State], [Category])
710-
VALUES (source.ProfileID, source.State, source.Category);
711-
TRUNCATE TABLE UpsertStagingTable
712-
END
713-
```
714-
715-
**Option 2:** You can choose to [invoke a stored procedure within the copy activity](#invoke-a-stored-procedure-from-a-sql-sink). This approach runs each batch (as governed by the `writeBatchSize` property) in the source table instead of using bulk insert as the default approach in the copy activity.
716-
717-
**Option 3:** You can use [Mapping Data Flow](#sink-transformation) which offers built-in insert/upsert/update methods.
689+
Copy activity now supports natively loading data into a database temporary table and then update the data in sink table if key exists and otherwise insert new data.
718690
719691
### Overwrite the entire table
720692

0 commit comments

Comments
 (0)