<!-- https://learnsql.cpetoday.com/functions/m/sql-databases -->
# Sql.Databases

Language: Power Query M
Category: Data sources
Syntax: Sql.Databases(server, optional options)
Summary: Lists the databases on a SQL Server, so you can see what is there before you connect to one.
Returns: A table with one row for each database, including its name.
Level: Intermediate
Related: Sql.Database, Value.NativeQuery, Excel.CurrentWorkbook, Csv.Document, Web.Contents

## 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
- `server`: the server name, with the port if needed, such as `"learnsql.cpetoday.com,1433"`.
- `optional options`: a record of settings, the same kind of record that Sql.Database accepts. Leave it out for a normal connection.

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

```powerquery
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
- Listing databases is a read of the server's catalog. Use it to find a name, not as part of every refresh.
- The list shows only the databases the sign-in can see. A missing database may be a permission issue, not a missing database.
- The sign-in and privacy rules are the same as for Sql.Database.
- Keep the chosen database name in a parameter, so that a change of server is made in one place.

## 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.
