Skip to content

Instantly share code, notes, and snippets.

@ArthurSteijn
Created December 8, 2020 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArthurSteijn/041d3076bcb36395678703ca63240e29 to your computer and use it in GitHub Desktop.
Save ArthurSteijn/041d3076bcb36395678703ca63240e29 to your computer and use it in GitHub Desktop.
-- 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