Forum Discussion
Azure Upsert Activity very slow with trigger
Hello shuhn1229
Your `AFTER UPDATE` trigger performs a correlated update on the entire table, which becomes inefficient for large batches
Optimized Approach would be to Use a JOIN instead of `IN` clause:
UPDATE w
SET ModifiedDate = GETDATE()
FROM [dbo].[WRSH] w
INNER JOIN inserted i ON w.Barcode = i.Barcode;
This leverages set-based operations more efficiently.
• Ensure `Barcode` is indexed (ideally clustered if it’s the primary key) to optimize the join operation
if trigger is not necessary
For high-throughput scenarios, consider temporal tables (Azure SQL feature):
ALTER TABLE [dbo].[WRSH] ADD
ModifiedDate datetime2 GENERATED ALWAYS AS ROW START HIDDEN DEFAULT GETUTCDATE(),
PERIOD FOR SYSTEM_TIME (ModifiedDate, Garbawgy);
Eliminates trigger overhead by auto-tracking changes.
• Provides built-in auditing without custom code.
- shuhn12291 year ago
Resolver I
Thank you very much, didn;t realize the second was even an option
- how sigjificant of a performance hit do you suspect I'll take with a copy activity for a table in the millions of source/sink with the temporal table
- If I delete the temporal column "ModifiedDate" will this revert the table to its previous form?
Thank you so very much