I have more than one Azure SQL Server which each may contain at least one SQL Elastic Pool. I am trying to build a SQL script that can execute a CREATE DATABASE statement on any of those servers and select one of the available pools on that server. To that end, I would like to know the T-SQL statement which would list all the available elastic pools on this server. I have found the SQL below which will list all the databases on the server and which pool they are in:
SELECT d.database_id, d.name, elastic_pool_name
FROM sys.databases d
JOIN sys.database_service_objectives dso ON d.database_id = dso.database_id
However, this only returns master
on a new server so I can't tell what the pool name(s) are to create a new database in a pool on the server. I also found this REST API endpoint to list all elastic pools on a server, but I need to execute this in SQL and not via HTTP.
You can get the list of elastic pools on the server from sys.elastic_pool_resource_stats
select distinct @@servername as servername, elastic_pool_name from sys.elastic_pool_resource_stats