BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

SQL SELECT Database – USE Statement

Last Updated: August 15, 2022 by Chaitanya Singh | Filed Under: SQL

In an ideal scenario, there are several databases present on an a database server. In order to perform an operation on data, you must first select the database using USE DbName statement and then you can perform an operation on a table, view or indexes.

It is important to select the database as more than one databases can have tables with the same name, if you are not selecting the database then you may accidentally perform an operation on a wrong database.

Syntax of USE statement

USE DbName;

USE is the keyword and DbName is the database name.

Example of USE statement in SQL

Generally we first list down all the databases before selecting the database, this make sure that we are scanning all the databases and selecting the right database.

SHOW DATABASES;

This command list down all the databases that are present on the database server.

Let’s say it lists down the following databases.

SQL> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| AbcTest            |
| Test               |
| Demo               |
| DB1                |
| Employee           |
+--------------------+
4 rows in set (0.00 sec)

To select the Employee database from the list, use the following statement.

USE Employee;

This will select the Employee database for the further SQL commands and queries.

After this statement whatever operation you will perform like Create table, delete table etc. would be performed on the database “Employee”.  Let’s say after making some modification, you may want to work with another database “Demo” then you can simply change the database by simply using the USE statement again.

USE Demo;

This will select the database “Demo” for the further SQL queries and processing of data.

Top Related Articles:

  1. Introduction to SQL
  2. SQL SELECT TOP Statement
  3. SQL CREATE DATABASE Statement
  4. SQL SELECT AVG() Function
  5. SQL SELECT COUNT

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

SQL Tutorial

  • SQL Tutorial
  • SQL Introduction
  • SQL Syntax
  • SQL Data Types

SQL Database

  • SQL CREATE DB
  • SQL DROP DB
  • SQL Rename DB
  • SQL USE DB

SQL Queries

  • SQL Select
  • SQL Select Distinct
  • SQL Select Count
  • SQL Select Top
  • SQL Where
  • SQL AND, OR & NOT
  • SQL Order By
  • SQL Insert Into
  • SQL Insert Into SELECT
  • SQL Select Random
  • SQL Alias
  • SQL NULL Check
  • SQL Update
  • SQL Delete
  • SQL MIN, MAX
  • SQL SUM
  • SQL AVG

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap