Create External Database Objects
Create External Database Objects
" 100 XP
You can use the OPENROWSET function in SQL queries that run in the default master database
of the built-in serverless SQL pool to explore data in the data lake. However, sometimes you
may want to create a custom database that contains some objects that make it easier to work
with external data in the data lake that you need to query frequently.
Creating a database
You can create a database in a serverless SQL pool just as you would in a SQL Server instance.
You can use the graphical interface in Synapse Studio, or a CREATE DATABASE statement. One
consideration is to set the collation of your database so that it supports conversion of text data
in files to appropriate Transact-SQL data types.
The following example code creates a database named salesDB with a collation that makes it
easier to import UTF-8 encoded text data into VARCHAR columns.
SQL
SQL
https://learn.microsoft.com/en-us/training/modules/query-data-lake-using-azure-synapse-serverless-sql-pools/4-external-objects 1/4
21/05/2024, 16:54 Create external database objects - Training | Microsoft Learn
One benefit of an external data source, is that you can simplify an OPENROWSET query to use
the combination of the data source and the relative path to the folders or files you want to
query:
SQL
SELECT *
FROM
OPENROWSET(
BULK 'orders/*.csv',
DATA_SOURCE = 'files',
FORMAT = 'csv',
PARSER_VERSION = '2.0'
) AS orders
In this example, the BULK parameter is used to specify the relative path for all .csv files in the
orders folder, which is a subfolder of the files folder referenced by the data source.
Another benefit of using a data source is that you can assign a credential for the data source
to use when accessing the underlying storage, enabling you to provide access to data through
SQL without permitting users to access the data directly in the storage account. For example,
the following code creates a credential that uses a shared access signature (SAS) to
authenticate against the underlying Azure storage account hosting the data lake.
SQL
Tip
In addition to SAS authentication, you can define credentials that use managed identity
(the Microsoft Entra identity used by your Azure Synapse workspace), a specific Microsoft
Entra principal, or passthrough authentication based on the identity of the user running
the query (which is the default type of authentication). To learn more about using
credentials in a serverless SQL pool, see the Control storage account access for
https://learn.microsoft.com/en-us/training/modules/query-data-lake-using-azure-synapse-serverless-sql-pools/4-external-objects 2/4
21/05/2024, 16:54 Create external database objects - Training | Microsoft Learn
serverless SQL pool in Azure Synapse Analytics article in Azure Synapse Analytics
documentation.
SQL
After creating file formats for the specific data files you need to work with, you can use the file
format to create external tables, as discussed next.
SQL
https://learn.microsoft.com/en-us/training/modules/query-data-lake-using-azure-synapse-serverless-sql-pools/4-external-objects 3/4
21/05/2024, 16:54 Create external database objects - Training | Microsoft Learn
(
DATA_SOURCE = files,
LOCATION = 'products/*.csv',
FILE_FORMAT = CsvFormat
);
GO
By creating a database that contains the external objects discussed in this unit, you can
provide a relational database layer over files in a data lake, making it easier for many data
analysts and reporting tools to access the data by using standard SQL query semantics.
https://learn.microsoft.com/en-us/training/modules/query-data-lake-using-azure-synapse-serverless-sql-pools/4-external-objects 4/4