Downloads
Power Query MData sourcesIntermediate

Sql.Databases

Lists the databases on a SQL Server, so you can see what is there before you connect to one.

Syntax
Sql.Databases(server, optional options)

Returns: A table with one row for each database, including its name.

What it does

Sql.Databases asks a SQL Server for the names of the databases it holds. Use it when you do not yet know the database name, for example when you are setting up a new report against a server that someone else manages. Once you know the name, Sql.Database is the function that opens the tables.

Syntax and arguments

Example

A new analyst needs the names of the databases on the reporting server before writing a query.

let
    Databases = Sql.Databases("learnsql.cpetoday.com,1433")
in
    Databases

Databases is a table with one row for each database on the server. Look at the column that holds the database names in the editor, then pick the one you need and use its name in Sql.Database. The server may hold some databases that you do not have permission to read, so the list is what the login can see.

Example: a second, different use

Filtering the list to databases with a given prefix, for example one per legal entity, using List.Select on the names.

Things to watch

In business terms

Finance systems are often split across several databases, one per company, year or business unit. Listing them first avoids typing the wrong name into a report that will be used for a close.

Related functions

All Power Query M functions · View as Markdown · M basics