SQL SELECT Database, USE Statement

Posted in /   /  

SQL SELECT Database, USE Statement

Vinay Khatri
Last updated on May 22, 2024

    If we have multiple Databases in our SQL schema then in order to operate on specific database first, we need to select that it then only we are capable of using the queries on that database. To select a database amongst the multiples ones we use the SQL USE command.


    Follow this syntax to select a specific database:

    USE data_base_name;

    As all the databases in an SQL schema have unique names so you are only able to select a single database using the USE command.


    First Check all the databases present in your SQL schema: Query



    | Database           |
    | contacts           |
    | information_schema |
    | music              |
    | mysql              |
    | performance_schema |
    | student_db         |
    | sys                |
    | world              |
    8 rows in set (0.00 sec)


    USE student_db


    Database changed

    The Output Database Changed signifies that now we can use the database student_db and now all the database commands like CREATE TABLE, SELECT, etc. are valid.

    Verify if you are using student_db database;

    If you have selected a database using the USE command now you can see all the tables reside in that database. To see all the tables of a database, use the SHOW TABEL commands; Example Query



    Empty set (0.07 sec)

    For now, we have not created any table in the student_db , that’s why we are getting the Empty set as an output.


    • First, we need to select a specific database in order to perform the queries on the tables and data.
    • To select a Database, we use the USE command.
    • Once we have selected a database now, we can perform the various operation on its tables and data.
    • To see all the tables, present in a database, first select the database then use the SHOW TABLES commands.

    People are also reading:

    Leave a Comment on this Post