I have a Azure Synapse SQL workspace. I want it to: (a) read the data from Azure blob storage, (b) run the SQL query, and (c) write the output back to Azure blob.
I got (a) and (b) above working — it runs the query by reading the data from blob. I am not able to write the output back to blob. I was just wondering how do I change my below SQL query to write to the blob.
SELECT * FROM
OPENROWSET(BULK 'https://myblob.blob.core.windows.net/testblob/',
FORMAT = 'CSV')
WITH
(
date1 DATETIME2,
media varchar(8000),
callconfig VARCHAR(8000),
count1 INT
) AS [callconfigTable]
It will be great if someone can help. Thank you!
2
Answers
You can use CETAS functionality:
https://learn.microsoft.com/en-us/azure/synapse-analytics/sql/develop-tables-cetas
That way you can write back data to blob via TSQL functionality.
Else you always have ADF/synapse pipelines to copy the select query into blob
If you want to set "DATA_SOURCE" and write SQL query output to blob storage.
Follow below approach:
As per MS_doc,
I reproduce same in my environment. I got this result.
First Create master key on database.
Create database Scope and credentials.
create external data source
Create external table:
Note:
the location should be like this as shown below image:
You can directly insert data into an external table by using the INSERT INTO command. The external table is already connected to the storage account.