Automatically load on-prem CSV data into Azure SQL  with Azure Functions
Image by https://buildazure.com/

Automatically load on-prem CSV data into Azure SQL with Azure Functions

Lately .csv (or related format, like .tsv) became very popular again, and so it’s quite common to be asked to import data contained in one or more .csv file into the database you application is using, so that data contained therein could be used by the application itself.

In the era of the Cloud, what can we do to simplify such popular requirement so that, for example, the user can just drop a file into a folder, and have it automagically imported into Azure SQL? (With small changes the same principle could be used for any database)

Azure Functions (that I love more and more every day) are the answer. Azure functions support the concept of trigger, which is an event that (as the name implies) when happens, will have an Azure Function executed, passing to that function information about the event that triggered it.

One of the available trigger is the Blob Trigger. So 40% of the work that is needed to implement what the title of this article says is already done.

The other 40% is provided by a (quite) new feature that has been added to the BULK INSERT command in Azure SQL: that ability to use a Blob Storage as a source.

The remaining 20% is the code that needs to be written to “glue” these two functionalities together. And this is the beauty of Azure Functions! Out of 100% of the code you would have had to write, you actually have to care only for 20% of it!

The full solution, with detailed instruction on how to set it up using, when possible, the new Azure CLI 2.0, is here:

https://github.com/yorek/AzureFunctionUploadToSQL

Each time a file will be saved into the Azure Blob Store's “csv” folder, within a couple of seconds, if the format is the expected one, data will be available in Azure SQL for you to be used as you wish. Yeah, is that simple and easy, really!

Enjoy!

I'm glad people like my art, but it's be nice if you gave attribution to BuildAzure.com for my image.

In case I need to use it several time and avoid duplicated import, or need to update record in SQL, is still feasible with this method?

Like
Reply

To view or add a comment, sign in

More articles by Davide Mauri

  • Lateral Thinking: Transitive Closure Clustering with SQL Server, UDA and JSON

    Calculating Transitive Closure Clusters using non-scalar UDA. And a bit of creativity.

  • Direct access to JSON files with Azure SQL

    No need to import files anymore: access json where it's stored Dealing with CSV or JSON data today is more and more…

  • Caching is not what you think it is

    Caching to solve performance problems? It may not be the best idea Let’s say it immediately and clearly: caching should…

    2 Comments
  • From ElasticSearch back to SQL Server

    Sharing with the community why we decided to move back from ElasticSearch to SQL Server Sometimes it happens: you move…

    9 Comments
  • Apache Zeppelin for SQL Server 0.7.1

    Updated to match the latest Apache Zeppelin release During this weekend I’ve updated the SQL Server version of Apache…

  • Data Juice

    The data ecosystem explained in 10 simple images Couple of weeks ago I was explaining how IoT and BigData can be a game…

    2 Comments
  • SQL Server Integration Services Dashboard

    I haven’t been working on Integration Services lately, but presenting at the SQL Saturday #613 in Redmond, WA, gave me…

    7 Comments
  • PASS Application Development Virtual Group

    I've been involved with PASS, once named Professional Association of SQL Server users, now just..

  • Apache Zeppelin for SQL Server v 0.7 R2

    Some nasty bug fixed Last weekend I worked on merging that latest changes done to Apache Zeppelin 0.7 to my fork of the…

  • Running Apache Zeppelin for SQL Server on Windows 10 natively

    No docker, just Java and Windows 10 I’ve finally had some “free” time to create a binary distribution package for…

Others also viewed

Explore content categories