11

Is there a way for an Azure function to be called every time a new database row is added to an SQL azure database ? Ideally without any timer based polling. I know this can be done on blob storage but dont see a way to do this on Azure function.

Thanks in advance

w2olves
  • 2,229
  • 10
  • 33
  • 60
  • 2
    Seeing as the accepted answer no longer answers the question, you might want to consider accepting the other answer instead. – Peter Morris Nov 02 '20 at 09:53

4 Answers4

8

Function Apps don't have an SQL trigger, but Logic Apps do, and it works for both on-premises SQL Server and Azure SQL Server. This will trigger when new rows are added, but do note it uses timer-based polling.

It

Cocowalla
  • 13,822
  • 6
  • 66
  • 112
4

It is possible but it's experimental right now. There's a guide that I'm putting at the end of this answer and you'll see that it's pretty straight forward. But again, this is experimental and don't expect that it works well all the time.

Another option will be in the code you have that insert a record to also send a message to queue o service bus and you can then make use of that as a trigger to your function (with service bus you also configure a dead letter queue for retries).

Reference: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-external-table

  • 2
    The referenced article no longer exists and looks like SQL server is no longer an offering for an Azure Function binding. – Lance Mar 05 '19 at 16:11
  • Only options to solve this currently is to communicate the event via code. E.g. After you save something to a table in your app, send an event via Event Grid/Service Bus topic or add a job to a Storage/Service Bus queue and have an Azure Func trigger on that. – GFoley83 Apr 09 '19 at 21:12
  • 1
    It seems SQL Server is indeed a valid binding now (although in preview and C# only), however it's not supported as a trigger. Only as input or output. Which is a dealbreaker for many use cases. – Adam Dec 06 '21 at 20:30
1
  1. Turn on Change Tracking in the SQL Database
  2. Use Azure Data Factory to write to Azure Table Storage
  3. Use that as a trigger for your funcion

ADF's documentation has a walkthrough for steps 1 and 2, except that they target Blob Storage (and reference Azure SQL throughout, except for a disclaimer at the top that it would also work with SQL Server).

Arithmomaniac
  • 4,604
  • 3
  • 38
  • 58
1

As of November 2022, Azure SQL trigger for functions is available (preview) for premium and dedicated plans. Unfortunately, it's not available for consumption plans.

Read about it here:

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

user1843640
  • 3,613
  • 3
  • 31
  • 44