Categories:

Database, Schema, & Share DDL

# SHOW DATABASES¶

Lists the databases for which you have access privileges across your entire account, including dropped databases that are still within the Time Travel retention period and, therefore, can be undropped.

The output returns database metadata and properties, ordered lexicographically by database name. This is important to note if you wish to filter the results using the provided filters.

DATABASES View (Information Schema)

## Syntax¶

SHOW [ TERSE ] DATABASES [ HISTORY ] [ LIKE '<pattern>' ]
[ STARTS WITH '<name_string>' ]
[ LIMIT <rows> [ FROM '<name_string>' ] ]


## Parameters¶

TERSE

Optionally returns output containing only the following columns:

• created_on

• name

• kind

• database_name

• schema_name

Note that kind, database_name, and schema_name always display NULL because the columns are not applicable for databases.

Default: No value (all columns are included in the output)

HISTORY

Optionally includes dropped databases that have not yet been purged (i.e. they are still within their respective Time Travel retention periods). If multiple versions of a dropped database exist, the output displays a row for each version. The output also includes an additional dropped_on column, which displays:

• Date and timestamp (for dropped databases).

• NULL (for active databases).

Default: No value (dropped databases are not included in the output)

LIKE 'pattern'

Optionally filters the command output by object name. The filter uses case-insensitive pattern matching, with support for SQL wildcard characters (% and _).

For example, the following patterns return the same results:

... LIKE '%testing%' ...
... LIKE '%TESTING%' ...

Default: No value (no filtering is applied)

STARTS WITH 'name_string'

Optionally filters the command output based on the characters that appear at the beginning of the object name. The string must be enclosed in single quotes and is case-sensitive. For example, the following return different results:

... STARTS WITH 'B' ...
... STARTS WITH 'b' ...

Default: No value (no filtering is applied)

LIMIT rows [ FROM 'name_string' ]

Optionally limits the maximum number of rows returned, while also enabling “pagination” of the results. Note that the actual number of rows returned may be less than the specified limit (e.g. the number of existing objects is less than the specified limit).

The optional FROM 'name_string' subclause effectively serves as a “cursor” for the results. This enables fetching the specified number of rows following the first row whose object name matches the specified string:

• The string must be enclosed in single quotes and is case-sensitive.

• The string does not have to include the full object name; partial names are supported.

Default: No value (no limit is applied to the output)

Note

Both FROM 'name_string' and STARTS WITH 'name_string' can be combined in the same statement; however, both conditions must be met or they cancel out each other and no results are returned.

In addition, objects are returned in lexicographic order by name, so FROM 'name_string' only returns rows with a higher lexicographic value than the rows returned by STARTS WITH 'name_string'.

For example:

• ... STARTS WITH 'A' LIMIT ... FROM 'B' would return no results.

• ... STARTS WITH 'B' LIMIT ... FROM 'A' would return no results.

• ... STARTS WITH 'A' LIMIT ... FROM 'AB' would return results (if any rows match the input strings).

## Usage Notes¶

• The command does not require a running warehouse to execute.

• The value for LIMIT rows cannot exceed 10000. If LIMIT rows is omitted, the command results in an error if the result set is larger than 10K rows.

To view results for which more than 10K records exist, either include LIMIT rows or query the corresponding view in the Information Schema.

• To post-process the output of this command, you can use the RESULT_SCAN function, which treats the output as a table that can be queried.

## Examples¶

Show all databases that you have privileges to view in your account:

SHOW DATABASES;

+---------------------------------+-----------+------------+------------+--------+--------+---------+---------+----------------+
| created_on                      | name      | is_default | is_current | origin | owner  | comment | options | retention_time |
|---------------------------------+-----------+------------+------------+--------+--------+---------+---------+----------------+
| Tue, 17 Mar 2015 16:57:04 -0700 | MYTESTDB  | N          | Y          |        | PUBLIC |         |         | 1              |
| Wed, 25 Feb 2015 17:30:04 -0800 | SALES1    | N          | N          |        | PUBLIC |         |         | 1              |
| Fri, 13 Feb 2015 19:21:49 -0800 | DEMO1     | N          | N          |        | PUBLIC |         |         | 1              |
+---------------------------------+-----------+------------+------------+--------+--------+---------+---------+----------------+


Show all databases that you have privileges to view in the system, including dropped databases (this example builds on the DROP DATABASE examples):

SHOW DATABASES HISTORY;

+---------------------------------+-----------+------------+------------+--------+--------+---------+---------+----------------+---------------------------------+
| created_on                      | name      | is_default | is_current | origin | owner  | comment | options | retention_time | dropped_on                      |
|---------------------------------+-----------+------------+------------+--------+--------+---------+---------+----------------+---------------------------------|
| Tue, 17 Mar 2015 16:57:04 -0700 | MYTESTDB  | N          | Y          |        | PUBLIC |         |         | 1              | [NULL]                          |
| Wed, 25 Feb 2015 17:30:04 -0800 | SALES1    | N          | N          |        | PUBLIC |         |         | 1              | [NULL]                          |
| Fri, 13 Feb 2015 19:21:49 -0800 | DEMO1     | N          | N          |        | PUBLIC |         |         | 1              | [NULL]                          |
| Wed, 25 Feb 2015 16:16:54 -0800 | MYTESTDB2 | N          | N          |        | PUBLIC |         |         | 1              | Fri, 13 May 2016 17:35:09 -0700 |
+---------------------------------+-----------+------------+------------+--------+--------+---------+---------+----------------+---------------------------------+