SQL > Data Definition Language (DDL) > USE

The USE keyword is used to select a database in MySQL and SQL Server. The syntax is as follows:

Key Takeaway: The SQL USE statement sets the active database so all subsequent queries run against that database by default. In MySQL, you can still access tables in other databases using the DatabaseName.TableName notation.

USE "database_name";

For example, if you want to connect to a database called "Scores", you can type in the following:

USE Scores;

In MySQL, you can access tables in multiple databases by specifying [Database Name].[Table Name]. If the table you want to access is currently in the database you use, there is no need to specify the database name.

For example, if you want to access table "Course_110" from database "Scores" and table "Students" from database "Personnel", you can type in the following:

USE Scores;

SELECT ...
FROM Course_110, Personnel.Students
WHERE ...
;

Frequently Asked Questions

What does the SQL USE command do?
The USE command selects a specific database to become active, so all subsequent SQL statements operate on that database without needing to prefix table names with the database name.
Can I query tables in multiple databases at once in MySQL?
Yes. In MySQL you can reference tables in other databases in the same query by using the DatabaseName.TableName notation. Only the default database requires no prefix.
Is USE supported in Oracle and PostgreSQL?
Oracle works with schemas rather than multiple databases in the same instance, so USE is not applicable. PostgreSQL uses the \c command in psql to switch databases.
What happens if I omit the USE command?
Without an active database, every table reference must be fully qualified with its database name (DatabaseName.TableName) in each query, which can make queries verbose.

Next: SQL CREATE DATABASE

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact