Open In App

SQL USE Database Statement

Improve
Improve
Like Article
Like
Save
Share
Report

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. 


Last Updated : 06 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads