SQL SELECT or USE DATABASE



SQL USE DATABASE Statement

The SQL USE DATABASE statement is used to select and switch to a specific database. This command sets the context for all subsequent SQL operations, ensuring that they are executed within the selected database. It is essential for managing and organizing data across multiple databases.


Syntax

USE database_name;
  • USE: This is the SQL keyword used to select a database.
  • database_name: This specifies the name of the database you want to select.

Example

Let's go through a complete example that includes creating a database, selecting the database, and then creating a table within the selected database.

Step 1: Creating a Database

This step involves creating a new database named example_db.

CREATE DATABASE example_db;

In this example, we create a database named example_db.

Step 2: Selecting the Database

This step involves selecting the newly created database to use it for subsequent operations.

USE example_db;

This command selects example_db as the current database, setting the context for all subsequent SQL commands.