1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

常にManaged ID 認証でOpen RowsetするViewを作りたいときに使うサンプル

Last updated at Posted at 2023-08-24
sql

CREATE DATABASE [cred_test] 
    COLLATE Latin1_General_100_BIN2_UTF8; -- お好みで
    -- https://techcommunity.microsoft.com/t5/azure-synapse-analytics-blog/always-use-utf-8-collations-to-read-utf-8-text-in-serverless-sql/ba-p/1883633
GO
USE [cred_test]
GO


-- CREATE DATABASE SCOPED CREDENTIALに必要
CREATE MASTER KEY    
GO

-- ストレージアカウントに接続する際に利用する資格情報を作成

CREATE DATABASE SCOPED CREDENTIAL [cred_synapsemsi]
WITH IDENTITY = 'Managed Identity'
GO

-- ストレージアカウントに対する接続を作成

IF NOT EXISTS (SELECT * FROM sys.external_data_sources WHERE name = 'msi_datalake_enrich')
    CREATE EXTERNAL DATA SOURCE [msi_datalake_enrich]
    WITH(
        CREDENTIAL = [cred_synapsemsi],
        LOCATION = 'https://testaccount.dfs.core.windows.net/30-enrich'
    )

--作成した接続を使用してクエリを行うと、クエリを実行したユーザーではなく、作成した資格情報=Synapse の権限でストレージアカウントにアクセスし、ユーザーにストレージアカウント上の権限を不要とできる

SELECT
    TOP 100 *
FROM OPENROWSET(
    BULK '/Refined/',
    DATA_SOURCE='msi_datalake_enrich', --> Root URL is in LOCATION of DATA SOURCE
    FORMAT = 'DELTA'
    ) AS [result]

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?