SQL USE Database Statement
Last Updated :
27 Dec, 2024
SQL(Structured Query Language) is a standard Database language that is used to create, maintain and retrieve the data from relational databases like MySQL, Oracle, etc. It is flexible and user-friendly. In SQL, to interact with the database, the users have to type queries that have certain syntax, and use command is one of them. The use command is used when there are multiple databases in the SQL and the user or programmer specifically wants to use a particular database. Thus, in simple terms, the use statement selects a specific database and then performs operations on it using the inbuilt commands of SQL.
Syntax:
USE database_name;
Example 1:
The user wants to works on the databases named "GEEKS". So the user will write:
USE candy;

Example 2:
Before using any database using the use command, it's necessary to first create it. In order to create a database in SQL, the following command is used. Here, we create a database named "GFG1":
CREATE DATABASE GFG1
Now, after the user has created a database named candy, we can use this database to perform the database operations. So, for that, the user has to type the USE command as follows:
USE GFG1
After performing desired operations on the database, if we do not want the database, We can drop the database using the DROP command:
DROP DATABASE GFG1

Remember, once a database is dropped, it's removed permanently from the list of available databases, there is no way to retrieve the data of the table or the complete database in any possible way.
After using the drop command, if the user types -
USE GFG1
The SQL database will throw an error as the GFG1 database has been removed permanently from the database using the drop command.
Similar Reads
SQL CASE Statement The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing
4 min read
SQL CREATE VIEW Statement The SQL CREATE VIEW statement is a very powerful feature in RDBMSs that allows users to create virtual tables based on the result set of a SQL query. Unlike regular tables, these views do not store data themselves rather they provide a way of dynamically retrieving and presenting data from one or ma
4 min read
SQL DELETE Statement The SQL DELETE statement is an essential command in SQL used to remove one or more rows from a database table. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the table retaining only the table structure, constraints, and schema. Whether you n
4 min read
PL/SQL CASE Statement PL/SQL stands for Procedural Language Extension to the Structured Query Language and it is designed specifically for Oracle databases it extends Structured Query Language (SQL) capabilities by allowing the creation of stored procedures, functions, and triggers. The PL/SQL CASE statement is a powerfu
4 min read
MySQL DELETE Statement In DBMS, CRUD operations (Create, Read, Update, Delete) are essential for effective data management. The Delete operation is crucial for removing data from a database. This guide covers the MySQL DELETE statement, exploring its syntax and providing examples. Understanding how DELETE works helps ensu
6 min read