×

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.

How to compare date in SQL

In this section, we will learn about how dates can be compared in SQL. We can compare any random date with another date stored in a column of a table.This comparison...

4 minutes read.

SQL Aggregate Operators

In SQL, the aggregate operators perform a calculation on multiple rows or multiple values of a single column and give the output a single value. Here, multiple rows of data are...

4 minutes read.

SQL FULL JOIN

In this section, we will help you understand the concept of the SQL FULL Join clause with a few examples. The SQL FULL Join query is executed to display the integrated...

3 minutes read.

How to use LIKE in SQL

In this SQL article, we will learn and understand how to use LIKE to the columns in the SQL tables. What is Like? Like is an operator in the SQL. It is...

7 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 WHERE Statement

SQL WHERE Statement Introduction WHERE clause is used to include a condition while fetching data from tables.When you have to specify a condition that has to be obeyed while data is...

9 minutes read.

SQL Handling Duplicate

Removing Duplicates using DISTINCT Keyword: By using the DISTINCT keyword in SQL we can remove duplicate characters from tables or databases. A table contains more duplicate values and duplicate values can cause...

4 minutes read.

Codd’s Rules in SQL

Codd’s Rules Dr. Edgar F. Codd, in 1985, laid down 13 fundamental rules after doing large-scale research on the Relational Model of databases. According to him, every database must follow these...

3 minutes read.

SQL Insert multiple rows

This article will deal with a new insertion method in SQL which inserts multiple rows at a time. Multiple records can be inserted at a time into a specific table with...

4 minutes read.

SQL Data Definition Language

Data definition language directly effects on the structure/schema of the database. CREATE, ALTER, DROP are the commands of DDL.CREATE: Creates new database, table, or view of table.ALTER: Modifies the database or...

3 minutes read.

SQL JOIN

As the name says, joins mean to merge something or to combine something. But in the case of SQL, joins mean to merge or combine two different tables. The Join clause...

12 minutes read.

How to Add Comments in SQL?

How to Add Comments in SQL Comments are text notes that are incorporated into the program to make the code easier to understand. In SQL, commenting is used to explain various sections...

2 minutes read.

SQL Primary Key

A field, which contains unique data in a table, is called a PRIMARY KEY (PK). It means, a PRIMARY KEY field must contain unique data in the table. A PRIMARY KEY...

4 minutes read.

SQL SELECT BETWEEN Operator

This SQL tutorial explains and helps us understand how to use the BETWEEN operator in the SELECT query with examples. The SQL SELECT BETWEEN operator retrieves the data from the table...

2 minutes read.

SQL NOT Operator

SQL NOT is a Boolean operator used with the WHERE clause. NOT operator shows the records if the expression is false. When we use the NOT operator, we fetch only...

7 minutes read.

How to Update Table in SQL?

How to Update Table in SQL Introduction UPDATE query is used to update a record in a table. UPDATE is a DML command, which operates on the data of the table and not...

4 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.

How to drop a column in SQL?

How to drop a column in SQL Introduction To delete a column from an already created table, one needs to use the ALTER command along with the DROP COLUMN clause. Syntax: ALTER TABLE tablename...

4 minutes read.

SQL SubQuery

The Sub-query in the SQL is the inner query placed or positioned inside another query, which is also known is the outer query. The inner query is embedded in the...

6 minutes read.