Sql.Databases

Accessing Data

Returns a table of databases available on a SQL Server instance.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Sql.Databases(server as text, optional options as nullable record) as table

Parameters

NameTypeRequiredDescription
servertextYesThe SQL Server hostname, IP address, or named instance (e.g., "localhost" or "myserver.database.windows.net").
optionsrecordNoAn optional record with connection options such as ConnectionTimeout and SqlCompatibleWindowsAuth.

Return Value

tableA navigation table of databases on the specified SQL Server instance.

Remarks

Sql.Databases connects to a SQL Server instance at the server level and returns a navigation table listing all databases accessible to the authenticated user. Each row in the result represents a database and includes a Data column containing that database's own navigation table — equivalent to the result of calling Sql.Database for that database. You can drill in to access schemas, tables, views, and stored procedures.

When to use Sql.Databases vs Sql.Database: Use Sql.Databases when you need to enumerate all databases on a server, dynamically select a database at runtime, or build cross-database queries that start at the server level. Use Sql.Database when you know the target database name in advance — it is more direct and performs better for single-database queries.

Authentication: The same authentication options as Sql.Database apply — Windows authentication, SQL Server authentication (username and password), or Microsoft Account for Azure SQL. Configure authentication in the Power Query credentials dialog, not in the M query itself.

Navigation structure: The result is a two-column table with Name (database name as text) and Data (a navigation table for that database). Drilling into Data reveals the schemas and tables within that database, using the same {[Schema="schemaName", Item="tableName"]} key record syntax as Sql.Database.

Query folding: Folding applies once you drill into a specific database and table. The server-level listing itself does not fold.

Key options: - ConnectionTimeout (duration) — maximum time to wait when establishing the server connection. - SqlCompatibleWindowsAuth (logical) — forces SQL Server-compatible Windows authentication mode, useful for certain gateway or Kerberos configurations.

Power BI Service: Azure SQL Database supports direct cloud refresh. On-premises SQL Server requires an on-premises data gateway.

Examples

Example 1: List all databases on a local SQL Server instance

```powerquery

Sql.Databases("localhost")

Example 2: List all databases on Azure SQL Server

```powerquery

Sql.Databases("myserver.database.windows.net")

Example 3: Drill into a specific database and table

```powerquery

let
    Server = Sql.Databases("localhost"),
    AdventureWorks = Server{[Name="AdventureWorks"]}[Data],
    Products = AdventureWorks{[Schema="Production", Item="Product"]}[Data]
in
    Products

Example 4: Extract just the list of accessible database names

```powerquery

let
    Source = Sql.Databases("localhost"),
    DatabaseNames = Source[Name]
in
    DatabaseNames

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks