Azure Functions Trigger for SQL DML Operations

PS 401 Reputation points
2023-07-03T17:37:57.9766667+00:00

All, I am looking for suggestions on Event based approach to trigger a DML operation.

Can we use Az Functions to invoke the DML operation in DB1.schema.TableA upon operation in DB2.schema.TableA ?

Here is the env details:

SQL Env - SQL Managed Instance.

I am open on any idea for event based approach.

Thank you!

Azure SQL Database
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-07-03T19:03:30.7366667+00:00

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-sql-trigger

    You can use Azure Functions to trigger SQL DML operations. Azure SQL trigger for Functions, which is currently in preview, allows you to do this. This trigger uses SQL change tracking functionality to monitor a SQL table for changes and trigger a function when a row is created, updated, or deleted.

    an example

    using System.Collections.Generic;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Extensions.Logging;
    using Microsoft.Azure.WebJobs.Extensions.Sql;
    
    namespace AzureSQL.ToDo
    {
        public static class ToDoTrigger
        {
            [FunctionName("ToDoTrigger")]
            public static void Run(
                [SqlTrigger("[dbo].[ToDo]", "SqlConnectionString")]
                IReadOnlyList<SqlChange<ToDoItem>> changes,
                ILogger logger)
            {
                foreach (SqlChange<ToDoItem> change in changes)
                {
                    ToDoItem toDoItem = change.Item;
                    logger.LogInformation($"Change operation: {change.Operation}");
                    logger.LogInformation($"Id: {toDoItem.Id}, Title: {toDoItem.title}, Url: {toDoItem.url}, Completed: {toDoItem.completed}");
                }
            }
        }
    }
    
    
    

    it's important to note that the Azure SQL trigger for Functions uses a polling loop to check for changes. If you have a high frequency of changes, this might impact the performance of your Azure Function and potentially increase costs as Azure Functions use a consumption model where costs are tied to execution times.

    1 person found this answer helpful.
    0 comments No comments

Your answer

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