SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL Data Types SQL OPERATORS SQL COMMANDS SQL Queries

SQL Database

SQL Create Database SQL DROP Database SQL SELECT Database

SQL Table

SQL TABLE SQL CREATE TABLE SQL COPY TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL DROP TABLE SQL UPDATE TABLE SQL INSERT TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT WHERE Clause SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT OR Operator SQL SELECT LIKE Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL WHERE Clause SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT INTO Statement SQL INSERT INTO SELECT

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL CROSS Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Cast Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL Aggregate Operators SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL SQL Formatter WEB SQL SQL Auto Increment Save Point in SQL space() function in SQL

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL

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.



ADVERTISEMENT
ADVERTISEMENT