Export data from Azure SQL to a blob storage using T-SQL

Alpár Rákosi 20 Reputation points
2024-09-30T08:35:16.95+00:00

Hello,

We would like to export the data from an Azure SQL table to the BLOB storage (ideally into Parquet files, but anything else is also acceptable if Synapse is able to read it). We would like to do this in T-SQL so we can lock the table while we are copying the data. We have created an external data source pointing to the BLOB storage and we are able to query the files stored in it with OPENROWSET, but we are not able to insert any data into it.

E.g.

INSERT INTO OPENROWSET(
    BULK 'Query.csv',
    DATA_SOURCE = 'MyAzureBlobStorage',
    FORMAT = 'CSV',
    FORMATFILE = 'formatquery.xml',
    FORMATFILE_DATA_SOURCE = 'MyAzureBlobStorage' )
VALUES(11, 12, 13, 'asdf')

throws the error “Failed to execute query. Error: Incorrect syntax near the keyword 'BULK'.”

Probably the way to do this would be to create an external table, but this seems to be different between SQL Server and Azure SQL, and in Azure SQL it is not possible to write the “table” into simple files.

Is it in any way possible to upload the data to the blob storage using T-SQL only?

Azure SQL Database
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,842 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nandan Hegde 32,336 Reputation points MVP
    2024-09-30T08:39:29.03+00:00
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.