Created
December 8, 2020 18:31
-
-
Save ArthurSteijn/041d3076bcb36395678703ca63240e29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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