MySQL USE Statement
MySQL USE Statement
In this tutorial, we will learn about MySQL USE Statement with some examples. The USE statement specifies he current default database. It is used to select the default database for the subsequent MySQL commands. We can switch to another database by issuing another USE statement.
Syntax
The general syntax of the USE statement is shown as follows:
USE <database_name>
This statement allows us to refer to the database tables without explicitly specifying the database where the table resides. For example, City table resides in the world database. Using this statement, we can refer to the table simply as City instead of world.City
Note that we can refer to tables in other database schema using the schema name as follows:
<schema_name>.<table_name>
Example
Let’s look at some examples.
To select a database named world as the current database, we need to issue the following command at the mysql> prompt.
mysql> USE world;
The semi-colon is optional for this statement. The ideal response for the command is ‘Database changed’
The world database remains the default until the end of the session or until another USE statement is issued. To switch to other database, we can issue another USE command.
To get Help
To get help, issue the following command
mysql> HELP USE
Common Error
Trying to use non existent database.
mysql> USE testdb;
ERROR 1049 (42000): Unknown database ‘testdb’
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/