Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- Create a database master key if one does not already exist, using your own password. This key is used to encrypt the credential secret in next step.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<PASSWORD>' ;
-- Create a database scoped credential with Azure storage account key as the secret.
CREATE DATABASE SCOPED CREDENTIAL AzureStorageCredential
WITH IDENTITY='SHARED ACCESS SIGNATURE' ,
SECRET = '<SHARED ACCESS SIGNATURE KEY>'
GO
;
-- Create an external data source with CREDENTIAL option.
CREATE EXTERNAL DATA SOURCE SqlOnDemandDemo_ds WITH (
LOCATION = 'https://<storageAccountName>.blob.core.windows.net',
CREDENTIAL = AzureStorageCredential
)
;
CREATE EXTERNAL FILE FORMAT parquetfile1
WITH (
FORMAT_TYPE = PARQUET,
DATA_COMPRESSION = 'org.apache.hadoop.io.compress.SnappyCodec'
)
;
-- Create an external table and export the results to the Storage Account
-- Example is based on AdventureWorks
CREATE EXTERNAL TABLE dbo.FactSalesOrder
WITH
(
LOCATION = '/<storageContainer>/FactSalesOrder',
DATA_SOURCE = SqlOnDemandDemo_ds,
FILE_FORMAT = parquetfile1
)
AS SELECT * FROM [dbo].[vFactSalesOrder]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment