DBAtlas · Database operations atlas

Change the active database / schema

Oracle

-- Change the default schema:
ALTER SESSION SET CURRENT_SCHEMA = hr;
-- Switch to a PDB (inside a CDB):
ALTER SESSION SET CONTAINER = pdb1;

CURRENT_SCHEMA changes only object name resolution, not privileges.

PostgreSQL

-- Switch to another DB inside psql (reconnects):
\c mydb
-- Schema search path (same connection):
SET search_path TO hr, public;

In PostgreSQL a connection is bound to a single database; changing the DB means reconnecting.

MySQL

USE mydb;

Changes the active schema without dropping the connection.

SQL Server

USE mydb;

Changes the batch context; subsequent commands run in this database.

MongoDB

use mydb

Switches even if the database does not exist; it is actually created when the first document is written.

Redis

SELECT 1
# Switches to a logical DB index between 0 and 15

In Cluster mode SELECT supports only 0; use key prefixes instead of logical DB separation.

Open in DBAtlas →