A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/developer-guide/python-connector/../../sql-reference/sql/use-database below:

Website Navigation


USE DATABASE | Snowflake Documentation

USE DATABASE

Specifies the active/current database for the session:

See also:

CREATE DATABASE , ALTER DATABASE , DROP DATABASE , SHOW DATABASES

Syntax Parameters
name

Specifies the identifier for the database to use for the session. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.

Usage notes Examples

The following example specifies the database to use for subsequent SQL commands:

The following example shows how commands that refer to objects using unqualified names produce different output after a USE command to switch databases. The schemas, tables, table data, and so on can differ from one database to another.

When the SHOW SCHEMAS command is run in the context of database_one, it produces output reflecting the objects in that database:

USE DATABASE database_one;
SHOW SCHEMAS ->> SELECT "created_on", "name" FROM $1 ORDER BY "created_on";

+-------------------------------+--------------------+
| 2025-07-11 14:34:24.386 -0700 | PUBLIC             |
| 2025-07-11 14:42:23.509 -0700 | TEST_SCHEMA        |
| 2025-07-11 14:42:29.158 -0700 | STAGING_SCHEMA     |
| 2025-07-11 14:45:43.124 -0700 | INFORMATION_SCHEMA |
+-------------------------------+--------------------+

Copy

After a USE command switches to the database_two database, the SHOW SCHEMAS command produces output reflecting a different set of objects:

USE DATABASE database_two;
SHOW SCHEMAS ->> SELECT "created_on", "name" FROM $1 ORDER BY "created_on";

Copy

+-------------------------------+--------------------+
| 2025-07-11 14:34:31.496 -0700 | PUBLIC             |
| 2025-07-11 14:43:04.394 -0700 | PRODUCTION_SCHEMA  |
| 2025-07-11 14:44:23.006 -0700 | DASHBOARDS_SCHEMA  |
| 2025-07-11 14:45:54.372 -0700 | INFORMATION_SCHEMA |
+-------------------------------+--------------------+

The following example changes from one database to another, then back to the original database. The name of the original database is stored in a variable. Run the following commands:

SELECT CURRENT_DATABASE();
SET original_database = (SELECT CURRENT_DATABASE());
USE DATABASE database_two;
SELECT CURRENT_DATABASE();
USE DATABASE IDENTIFIER($original_database);
SELECT CURRENT_DATABASE();

Copy

The output for these commands shows how the current database value changes:

>SELECT CURRENT_DATABASE();
+--------------+
| DATABASE_ONE |
+--------------+

>SET original_database = (SELECT CURRENT_DATABASE());

>USE DATABASE database_two;
>SELECT CURRENT_DATABASE();
+--------------+
| DATABASE_TWO |
+--------------+

>USE DATABASE IDENTIFIER($original_database);
>SELECT CURRENT_DATABASE();
+--------------+
| DATABASE_ONE |
+--------------+

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4