Hi, I'm Ask INFA!
What would you like to know?
ASK INFAPreview
Please to access Ask INFA.

Prerequisites to connect to a serverless SQL pool

Prerequisites to connect to a serverless SQL pool

Reading data using OPENROWSET query

Reading data using OPENROWSET query

You can read data from a file in Microsoft Azure Data Lake Storage Gen2 using the OPENROWSET query.
  1. On the Azure portal, navigate to the workspace you created.
  2. Access
    Open Synapse Studio
    .
    This image displays the option to access synapse studio.
  3. Navigate to
    Data
    , click the
    Linked
    tab.
    This image displays the option to create an SQL database.
  4. Right-click a file and select
    Select Top 100 rows
    to use OPENROWSET query.
    If you configure Azure Active Directory or Managed Identity authentication, you can use the following command to create the query:
    SELECT
    TOP 100 *
    FROM
    OPENROWSET(
    BULK '0001/customer.parquet',//Relative path
    FORMAT = 'PARQUET'
    ) AS [result]
  5. If you configure Microsoft SQL authentication, perform the following additional steps before you create the query:
    1. Access Microsoft SQL Server Management Studio, Azure Data Studio, or any other tool that allows access to Azure database and run the following command to create master key:
      IF NOT EXISTS (SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)
      CREATE MASTER KEY
    2. Run the following command to create database scoped credentials:
      IF NOT EXISTS (SELECT * FROM sys.database_credentials WHERE NAME = '<Credential_Name>')
      BEGIN
      CREATE DATABASE SCOPED CREDENTIAL <Credential_Name>WITH IDENTITY = '<Identity_Name>', Secret = 'XXXXXX'
      END
      Only Service Principal authentication or Managed Identity authentication is applicable when you create database scoped credentials.
    3. Run the following command to create external data source:
      IF NOT EXISTS (SELECT * FROM sys.external_data_sources WHERE name = '<Data_Source_Name>')
      CREATE EXTERNAL DATA SOURCE <Data_Source_Name>
      WITH (
      LOCATION = '<Location>',
      CREDENTIAL = <Credential_Name>)//Credentials created in previous step
    4. Run the following command to create openrowset query:
      SELECT
      TOP 100 *
      FROM
      OPENROWSET(
      BULK '0001/customer.parquet',//Relative path
      DATA_SOURCE = 'adapterqa-source_adlsgen2qa_dfs_core_windows_net1',//Mandatory for SQL authentication.
      Ensure that the name of the data source matches with the name of the data source created in the previous step.
      FORMAT = 'PARQUET'
      ) AS [result]
    You cannot execute OPENROWSET queries on master database.

0 COMMENTS

We’d like to hear from you!