×

MySQL database queries

MySQL database queries

Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform operations on the database known as database queries. SQL has several queries for each work on data, and each query is used at a specific time and place.

The work of each query is different in MySQL. In this article, we will discuss the queries used for the database.

Create MySQL database

Here we will learn to create a database in MySQL. The database is like a giant box where many data are stored and divided into tables, columns, and rows.

MySQL understands SQL, so we will discuss the language used to create a database in MySQL. We will also run the syntax in MySQL to check the output.

The syntax used to create a database is:

CREATE DATABASE database_name;

Note: SQL command is not case sensitive to write in any way, but the statement should be correct.

The above statement is used to create a database in MySQL. In this, the‘database_name’ is the name of the database(name can be anything virtual or objective according to your choice).

For example: Let's create a database having the name SCHOOL in MySQL and check the result.

MySQL database queries

We cansee that by using the above syntax, the database SCHOOL has been created successfully.

Show MySQL database

After creating a database in MySQL, we have to check whether the database is created or not. We can do this by using another statement that isa show statement. After using this statement, all the database that has been created will be shown in a list.

Syntax to show the database:

SHOW DATABASES;

For example, we can check whether the above database SCHOOL is created or not as below.

MySQL database queries

In this image, we can see that the database SCHOOL is available in a list. It means the database is created successfully.

Use MySQL database

We can have several databases in MySQL, and we have to select any existing database to operate in it. Any operation that has to be performed in the table should be used only when the database is selected.

To select a database, we use the below syntax:

USE database_name;

For example, We have a database SCHOOL. To create a table or perform any other operation, we first need to select it. Let's use the syntax in MySQL and see the result.

MySQL database queries

Here we see that the database has been changed and ready to operate.

Delete MySQL database

This statement is used to delete the database from MySQL. After executing this statement, all the data, including tables, will be deleted permanently. MySQL provides the DROP statement to delete the database.

Syntax to delete the database:

DROP DATABASE database_name;

For example, we have a database SCHOOL. Let's delete this database using the below syntax in MySQL.

MySQL database queries

Here we see that the DROP statement deletes the database SCHOOL. If we want to use this database again, it shows the error.

Note: We must be careful while using the DROP statement because we cannot get it back once the database is deleted. This statement deletes the whole database permanently.


Related Topics

MySQL variable

The MySQL variable is essential for storing data in the table. The variable declares data with a specific name or label to avoid confusion. This data label is used in...

6 minutes read.

MySQL database queries

MySQL database queries Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform...

3 minutes read.

MySQL Database Introduction

MySQL - Database Introduction: The database plays an essential role in MySQL for storing and modifying the data. The database creates and keeps multiple tables. The database organizes and manipulates...

8 minutes read.

MySQL PI() function

In this context, we will learn how we can use the MySQL PI() function with proper syntax and good examples. Introduction of MySQL PI() function PI() function in MySQL is used to...

2 minutes read.

MySQL Aggregate function

The aggregation function works on the multiple values and returns single value output.  It makes the advanced and complex operation simple. The summation (SUM), MAX, AVG, MIN, COUNT functions are...

5 minutes read.

MySQL PERIOD_DIFF() function

In this context, we will learn how we can use the MySQL PERIOD_DIFF() function with proper syntax and good examples. Introduction of MySQL PERIOD_DIFF() function This function in MySQL is used to...

2 minutes read.

MySQL MIN function

The MIN() function determines the minimum or lowest value of the data set. This function works on numerical data type values. If the table displays zero value, then the row...

4 minutes read.

MySQL DATE_FORMAT() function

In this context, we will learn how we can use the MySQL DATE_FORMAT() function with proper syntax and good examples. Introduction of MySQL DATE_FORMAT() function DATE_FORMAT() function in MySQL is used to...

3 minutes read.

MySQL RIGHT JOIN

MySQL right join links two tables with each other. The left table column connects with the complete right side table. Each row of the right table tries to connect with...

4 minutes read.

MySQL Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 minutes read.

MySQL DAY() function

In this context, we will learn how we can use the MySQL DAY() function with proper syntax and good examples. Introduction of MySQL DAY() function This function in MySQL is used to...

2 minutes read.

MySQL Command line client Basic Queries

MySQL – command line client Basic Queries There are many queries to work with the MySQL command-line client. Today, we will explore MySQL basic queries and their function. The MySQL query...

8 minutes read.

MySQL REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL Character Length Function

In this context, we will learn how we can use the MySQL CHARACTER_LENGTH() function with proper syntax and good examples. Introduction of MySQL CHARACTER_LENGTH() function CHARACTER_LENGTH() function in MySQL is used to...

2 minutes read.

MySQL SELF JOIN

This join links table with itself. The inner join, a self join, a right join, and a cross join are connected with two or more two tables. But, the "self...

4 minutes read.

MySQL function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

9 minutes read.

MySQL Vs MongoDB

What is MongoDB? MongoDB is a distributed, open-source, cross-platform document-based database which was created to scale and develop applications simply. It was created as a NoSQL database by MongoDB Inc. MongoDB gets...

6 minutes read.