Lesson 4 of 4 Change Detection and Event-Driven Integration

Azure Functions and Logic Apps Triggers for SQL

This lesson explains the Azure Functions SQL trigger binding, Logic Apps SQL connector triggers and how to choose a change-handling method.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how the Azure Functions SQL trigger binding works.
  • Identify the requirements of the Logic Apps SQL triggers.
  • Choose a change-handling method for a scenario.

Azure Functions SQL trigger binding

The SQL trigger binding runs a function when rows in a table change. It is built on Change Tracking, which must be enabled on the database and the table, and it polls the change table, passing batches of changes (each with the row's current values and the operation) to the function. It keeps its state in lease tables in an az_func schema, so several function instances can share the work and resume after restarts. SQL input and output bindings read and write rows from the same function, which makes it straightforward to call an embedding model for changed rows and write the vectors back.

# Python (v2 programming model)
@app.sql_trigger(arg_name="changes", table_name="Catalog.Product",
                 connection_string_setting="SqlConnectionString")
def product_changed(changes: str) -> None:
    for change in json.loads(changes):
        if change["Operation"] in (0, 1):          # 0 = insert, 1 = update, 2 = delete
            refresh_embedding(change["Item"]["ProductID"])
True or false

The SQL trigger binding

Exam skills 2.4.7 · 3.1.3

Decide whether each statement about the Azure Functions SQL trigger is true.

Log in to try this activity Interactive activities are free with an account.

Logic Apps SQL connector triggers

Azure Logic Apps builds low-code workflows with the SQL Server connector, whose triggers poll a table on a schedule: When an item is created requires an IDENTITY column, and When an item is modified requires a ROWVERSION column. The workflow can then call APIs, send messages, call Azure OpenAI or write back to the database through connector actions. Logic Apps suits integration workflows that business teams maintain, with minutes of latency acceptable.

Choosing a method

The following table summarizes the change-handling options in this module and in table triggers.

MethodLatencyCapturesBest for
Table triggerSynchronousRows in the statementQueuing work inside the transaction; never slow calls
Change Tracking (polled)Polling intervalKeys and operationCustom sync and batch jobs
CDCSeconds (log reader) plus pollingBefore and after values of every changeAuditing and ETL
Change event streamingNear real time, pushedCloudEvents with old and new valuesEvent-driven fan-out to many consumers
Azure Functions SQL triggerSeconds (polls Change Tracking)Changed rows' current valuesServerless code per change, such as re-embedding
Logic Apps SQL triggerPolling interval (minutes)New or modified rowsLow-code integration workflows
Match the pairs

Choosing a change method

Exam skills 2.4.7

Match each requirement with the change-handling method that fits it.

Log in to try this activity Interactive activities are free with an account.
Worked example

Serverless re-embedding

When a support article is inserted or updated, its embedding must be regenerated within a minute by code that calls Azure OpenAI. The team wants serverless compute and no polling code of its own, and article writes must not slow down. What should the developer build?

Enable Change Tracking on the database and the Articles table and create an Azure Function with the SQL trigger binding that receives changed articles, calls the embedding model and writes the vectors with an output binding. The binding handles polling, batching and leases. A table trigger calling Azure OpenAI would slow writes and fail them when the model is unavailable, and a Logic Apps polling workflow is better suited to low-code integration with looser latency.

Check yourself

Which column does the Logic Apps 'When an item is modified' SQL trigger require?

Show answer

A ROWVERSION column; 'When an item is created' requires an IDENTITY column.

Exam Tips

Remember for the exam

  • Azure Functions SQL trigger requires Change Tracking on the database and table.
  • Logic Apps: When an item is created needs IDENTITY; When an item is modified needs ROWVERSION.
  • Triggers should only queue work; slow calls belong in asynchronous processes.
  • Choose by latency, what is captured and who maintains the logic.