×

SQL SELECT Database

In this tutorial, we will help you to understand and learn how to select the database in SQL with the help of examples.

The database user or the administrator wants to create the tables, indexes, and views in the already present database in the SQL. We must select the database already in the SQL Server to create these objects.

The database users and the administrators can select the database from the server by executing the USE keyword followed by the database name in SQL.

The syntax of the select database is as follows:

USE Database_Name;

In the above syntax, we have used the USE keyword followed by the database name present in the Structured Query Language to select the database.

Let’s understand how to select the database with the help of examples.

Before selecting the database, we must be known the database name already present on the server. To be familiar with the database inside the server, we will execute the SHOW DATABASES query shown below:

SHOW DATABASES;

The output of the above query is as follows:

Database
Copy
Ids
Information_schema
Javatpoint
Mumbai
Mysql
Performance_Schema
Phpadmin
Registration
Student
Student_1
Testdb
Wordpress
World

Example 1: Suppose we want to create the tables, views, and indexes inside the ids name database, then we will execute the below query to select the ids database as shown below:

USE Ids;

In the above query, we have selected the Ids database, and now we are ready to create the tables, views, and indexes inside the ids database.

The output of the query is as follows:

SQL SELECT Database

The Ids database is now selected, and we are ready to create the tables, views, and indexes inside the ids database.

Example 2: Suppose we want to create the tables, views, and indexes inside the copy name database, then we will execute the below query to select the copy database as shown below:

USE copy;

In the above query, we have selected the copy database, and now we are ready to create the tables, views, and indexes inside the copy database.

The output of the query is as follows:

SQL SELECT Database

The copy database is now selected, and we are ready to create the tables, views, and indexes inside the copy database.

Suppose we want to work on another database not present on the server. For this, we will create the new database and execute the USE keyword followed by that database name to select the database.

Let’s create the new database name Sports as shown in the below query:

CREATE DATABASE Sports;

Now, we will execute the SHOW DATABASES query to check whether the Sports database has been created successfully or not:

SHOW Databases;

The output of the above query is as follows:

Database
Copy
Ids
Information_schema
Javatpoint
Mumbai
Mysql
Performance_Schema
Phpadmin
Registration
Sports
Student
Student_1
Testdb
Wordpress
World
SQL SELECT Database

As we can see, the sports named database is successfully created. Now, we are ready to select the Sports named database.

Example 3: Suppose we want to create the tables, views, and indexes inside the Sports name database, then we will execute the below query to select the Sports database as shown below:

USE Sports;

In the above query, we have selected the Sports database, and now we are ready to create the tables, views, and indexes inside the Sports database.

The output of the query is as follows:

SQL SELECT Database

The Sports database is now selected, and we are ready to create the tables, views, and indexes inside the Sports database.

Let’s create another new database name Player, as shown in the below query:

CREATE DATABASE Player;

Now, we will execute the SHOW DATABASES query to check whether the Sports database has been created successfully or not:

SHOW Databases;

The output of the above query is as follows:

Database
Copy
Ids
Information_schema
Javatpoint
Mumbai
Mysql
Performance_Schema
Phpadmin
Player
Registration
Sports
Student
Student_1
Testdb
Wordpress
World
SQL SELECT Database

Example 4: Suppose we want to create the tables, views, and indexes inside the Player name database, then we will execute the below query to select the Player database as shown below:

USE Player;

In the above query, we have selected the Player database, and now we are ready to create the tables, views, and indexes inside the Player database.

The output of the query is as follows:

SQL SELECT Database

The Player database is now selected, and we are ready to create the tables, views, and indexes inside the Player database.


Related Topics

How to delete column in table

Introduction In SQL, sometimes it is required to delete a column of a table.The use of ALTER TABLE command with DROP COLUMN clause will serve the purpose to delete/remove a column...

4 minutes read.

SQL Data Types

In SQL DATA TYPES, each column holds value. Data types can be an integer type, character type, etc., and such data is stored in the database table. The data type is...

4 minutes read.

Update Query in SQL

Update is an SQL command that is used to modify the data that in already present in database. Update is a command of DML. DML means Data Manipulation Language. Basically,...

3 minutes read.

Types of SQL JOIN

The SQL JOIN combines one or more than one tables based on their relationship. The SQL JOIN involves a parent table and a child table relationship. There are different types of...

10 minutes read.

How to Create Temporary Table in SQL?

How to Create Temporary Table in SQL  Introduction to Temporary Tables Temporary table is a table which is used to store temporary data that can be used further in the same client...

3 minutes read.

SQL CASE

This page contains all the information about SQL CASE. The CASE is an If-Else type of logical query used in the statement. The CASE in Structured Query Language is similar...

5 minutes read.

Pattern Matching in SQL

The LIKE in the Structured Query Language is a Logical Operator. The SQL LIKE is used within the WHERE clause in the SQL. This Like Operator is used with the...

5 minutes read.

SQL INSERT INTO Statement

SQL INSERT INTO statement adds data to the newly created tables or existing tables. We can add single records or multiple records in a table by using this query. There are...

3 minutes read.

SQL INTERSECT

SQL intersect operator is used to combine two or more SELECT statements, but it only displays the data similar to the SELECT statement. The syntax for the INTERSECT operation: SELECT COLUMN_NAME1, COLUMN_NAME2,...

3 minutes read.

How to Add Foreign Key in SQL?

How to Add Foreign Key in SQL Foreign key is an attribute or a set of attributes that references to primary key of same table or another table (relation). Foreign key creation along...

4 minutes read.

SQL Arithmetic Operators

This page contains all the information, learn about SQL Arithmetic Operators concept in the SQL table with the help of examples. The Arithmetic Operators is used to perform mathematical calculations on...

5 minutes read.

SQL Tutorial for Beginners

SQL tutorial provides basic and advanced concepts of Structured Query Language and how you deploy SQL to work with a relational database system. Our SQL tutorial is designed for beginners...

3 minutes read.

SQL Commands

SQL commands are classified into four groups on the basis of their nature. DDL (Data Definition Language) DML (Data Manipulation Language) DCL (Data Control Language) DQL (Data Query Language) NOTE: This...

1 minute read.

SQL Alter Table

In Structured Query Language, if you want to add columns in an existing table, then modify the table, or delete columns from the table. All these operations are allowed only...

7 minutes read.

SQL Select Distinct

The SQL DISTINCT query is used to fetch unique values from the tables using the SELECT statement in the SQL. There may be a situation that arises when you want to...

4 minutes read.

SQL Topological Sorting

It is for Directed Acyclic Graph, which linearly describes the ordering of graphs. It is not possible for all graphs, it is possible for only Directed acyclic graphs. Applications of Topological...

3 minutes read.

DDL Commands in SQL

DDL stands for Data Definition Language. Data Definition Language is a bunch of SQL commands used to create, modify and delete Database schema but not the records or data. Data Definition...

5 minutes read.

Commit and Rollback in SQL

In Structured Query Language, we have Data Definition Language (DDL) and Data Manipulation Language (DML) commands the same way we have Transaction Control Language (TCL) commands in the Structured Query...

4 minutes read.

Where vs Having

Difference Between Where and Having The WHERE and HAVING clauses in SQL are used to filter records stored in tables in the databases. The dissimilarities between the WHERE and HAVING clause...

3 minutes read.

SQL SELECT SUM

The SQL Sum() function is an aggregate function in SQL that returns the total values of an expression. The expression may be numerical, or it may be an expression. Syntax: SELECT SUM(columnname)...

3 minutes read.