A database server can contain multiple databases. Before performing operations such as creating tables, inserting data, or retrieving records, a user must first select the database in which they want to work.
The USE statement is used to select a specific database and make it the current working database. Once a database is selected, all SQL operations will be performed within that database unless another database is selected.
The USE statement is used to select or switch to a particular database in the database server so that all subsequent SQL queries are executed in that database.
USE database_name;
When the USE command is executed:
CREATE TABLE, INSERT, SELECT, etc., will apply to that database.USE student_db;
After executing this command, student_db becomes the current database.
Now any table created will be stored inside this database.
Example:
CREATE TABLE students (
id INT,
name VARCHAR(50),
course VARCHAR(50)
);
The students table will be created inside the student_db database.
To check which database is currently selected, the following query can be used:
SELECT DATABASE();
Example Output:
| DATABASE() |
|---|
| student_db |
This shows that student_db is the currently active database.
USE command.USE is used to select a database for performing operations.The USE statement is an important command in DBMS that allows users to select the database they want to work with. By setting a database as the current working database, users can easily perform operations such as creating tables, inserting data, and retrieving records within that specific database.