USE changes the execution context of a session to a specified database or schema. After the statement runs, any unqualified table, view, or procedure reference is resolved in the chosen database until another USE is issued or the session ends. The statement does not create a new connection; it only switches context on the existing one.USE is not part of the ANSI SQL standard. It is available in MySQL, MariaDB, SQL Server, Snowflake, SAP HANA, Teradata, and other systems, but it is absent in PostgreSQL, SQLite, and Oracle. Dialects that lack USE offer alternatives such as setting the search_path (PostgreSQL) or attaching additional databases (SQLite).Because USE affects every subsequent statement in the session, scripts that mix multiple databases should issue USE immediately before the block of statements it governs and document the change clearly. Many teams prefer to open separate connections instead of switching context inside a script to reduce human error.USE cannot be executed inside an explicit transaction in some systems (for example, SQL Server); attempting to do so will throw an error. In others (MySQL) it is allowed but still discouraged because it can make rollback logic confusing.
database_name
(identifier) - Name of the database (or, in some dialects, schema) to become the defaultMySQL 3.x and SQL Server 6.0 (1995)
USE changes the default database or schema for your current session so that subsequent queries run against the selected database.
PostgreSQL does not implement USE. Open a new connection to the target database or use SET search_path to change schemas.
Yes. Terminate USE with a semicolon so the client knows the statement is complete.
Simply issue another USE pointing to the original database, or close and reopen your connection which resets the context.