Migrate to Innovate Summit:
Learn how migrating and modernizing to Azure can boost your business's performance, resilience, and security, enabling you to fully embrace AI.Register now
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Elastic database query (preview) for Azure SQL Database allows you to run T-SQL queries that span multiple databases using a single connection point. This article applies to vertically partitioned databases. In this article, learn how to configure and use an Azure SQL Database to perform queries that span multiple related databases.
The permission ALTER ANY EXTERNAL DATA SOURCE is required. This permission is included with the ALTER DATABASE permission. ALTER ANY EXTERNAL DATA SOURCE permissions are needed to refer to the underlying data source.
Create the sample databases
To start with, create two databases, Customers and Orders, either in the same or different logical servers.
Execute the following queries on the Orders database to create the OrderInformation table and input the sample data.
The master_key_password is a strong password of your choosing used to encrypt the connection credentials.
The username and password should be the username and password used to sign in into the Customers database (create a new user in Customers database if one doesn't already exists).
To create an external data source, execute the following command on the Orders database to connect to the Customers database. Provide the Azure SQL logical server of the Customers database in the LOCATION.
Use the sp_execute_remote stored procedure to execute a Transact-SQL statement on a single remote Azure SQL Database or set of databases serving as shards in a horizontal partitioning scheme. The following remote T-SQL query returns data from the external OrderInformation table.
SQL
EXEC sp_execute_remote
N'MyElasticDBQueryDataSrc',
N'SELECTCOUNT(CustomerID) AS customer_count FROM CustomerInformation';
Execute a sample elastic database T-SQL query
Once you define your external data source and your external tables, you can now use T-SQL to query your external tables. Execute this query on the Orders database:
SQL
SELECT OrderInformation.CustomerID, OrderInformation.OrderId, CustomerInformation.CustomerName, CustomerInformation.Company
FROM OrderInformation
INNERJOIN CustomerInformation
ON CustomerInformation.CustomerID = OrderInformation.CustomerID;
Cost
Currently, the elastic database query feature is included into the cost of your Azure SQL Database.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
sp_execute_remote executes a Transact-SQL statement on a single remote Azure SQL Database or set of databases serving as shards in a horizontal partitioning scheme.