TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL USE Statement

Overview

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’

MySQL USE statement

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/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL DROP DATABASE Statement› MySQL Datatypes

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version