×

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

SQL Operators

Arithmetic Operators Arithmetic operators are +, -, *, /, % performs addition, subtraction, multiplication, division, modulo respectively. Example:   Select 100+222; Select salary+100 From teacher Where teacher_id=1; Following output screen shows different arithmetic operations. We...

2 minutes read.

How to use GROUP BY clause in SQL

In this SQL article, we will learn about the GROUP BY clause and how to use it in SQL. We will also discuss using the GROUP BY clause with the...

6 minutes read.

SQL Aliases

SQL Aliases: These are used to give a temporary name for a column or table. These are used to make tables or columns more readable. These are used to rename the table...

2 minutes read.

SQL Data Control Language

Data Control Language decides to whom should (which user) permit access privileges. GRANT and REVOKE are the commands of DCL. GRANT: It gives privileges to user. REVOKE: It takes back privileges from granted...

1 minute 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.

How to create a database in SQL?

How to create a database in SQL It is very necessary to create a database in order to store the data into the database.Database name must always be unique.SQL does not...

6 minutes read.

SQL SELECT IN

SQL SELECT IN is a logical operator in Structured Query Language. It is used in SQL queries to reduce the use of multiple 'OR' operators. s The IN operator in SQL...

6 minutes read.

SQL Wildcards

SQL WILDCARD CHARACTERS: SQL wild card character is used to substitute zero or more characters of a string. These characters are used with the “LIKE” operator. Wild Card Characters in SQL: %_[]^- “%” : It is...

3 minutes read.

SQL COPY Table

In this tutorial, we will learn how to copy tables in SQL with the help of examples. Using the SELECT INTO statement in the SQL we can copy one table into...

4 minutes read.

SQL Right Join

The SQL Right Join query displays all the table records and similar records from the left table. The query display zero records if it doesn’t find any similar records. If...

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

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.

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

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 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 add column in table in SQL ?

How to add column in table in SQL  Introduction To add a column in already created table, one needs to use the ALTER command along with the ADD clause.If in the query,...

7 minutes read.

SQL CREATE TABLE

In SQL tutorial, we learned and created different databases. To stores data in databases, we need to create a table. To create the table, we need to use CREATE TABLE...

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