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"])The SQL trigger binding
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.
| Method | Latency | Captures | Best for |
|---|---|---|---|
| Table trigger | Synchronous | Rows in the statement | Queuing work inside the transaction; never slow calls |
| Change Tracking (polled) | Polling interval | Keys and operation | Custom sync and batch jobs |
| CDC | Seconds (log reader) plus polling | Before and after values of every change | Auditing and ETL |
| Change event streaming | Near real time, pushed | CloudEvents with old and new values | Event-driven fan-out to many consumers |
| Azure Functions SQL trigger | Seconds (polls Change Tracking) | Changed rows' current values | Serverless code per change, such as re-embedding |
| Logic Apps SQL trigger | Polling interval (minutes) | New or modified rows | Low-code integration workflows |
Choosing a change method
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.
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.