×

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 QUARTER() function

In this context, we will learn how we can use the MySQL QUARTER() function with proper syntax and good examples. Introduction of MySQL QUARTER() function The QUARTER() function in MySQL returns the...

3 minutes read.

MySQL POW() function

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

2 minutes read.

MySQL MAX function

The MAX function is a type of aggregation function that determines the maximum value of the table data. This function works on numerical data type values. If the table displays...

4 minutes read.

find_in_set() function in MySQL

This Function is used for finding the position of a particular string from the list of strings. For suppose if the specified string is repeated multiple times, then this functions...

4 minutes read.

MySQL ROUND() function

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

3 minutes read.

MySQL LN() function

In this context, we will learn how we can use the MySQL LN() function with proper syntax and good examples. Introduction of MySQL LN() function For evaluation of the natural logarithm of...

2 minutes read.

MySQL NATURAL JOIN

The natural join combines multiple tables using a column with the same name and data type. This operation combines a row of the two tables using common columns. This join...

4 minutes read.

MySQL CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

3 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 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 Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL Unique index

It helps to maintain data integrity to enforce the uniqueness of values in one or more columns. We can create more than one UNIQUE index in a single table, which...

3 minutes read.

MySQL Index

An index is a widely used method to access table information quickly. MySQL requires an index for operating table data stored in rows and columns. It's an entry point of...

3 minutes read.

MySQL Composite Index

Composite Index A composite index is an index that is used on multiple columns. MySQL management system manages multiple columns simultaneously. Therefore, the single index contains multiple columns in one query...

3 minutes read.

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 String Function

The string function is used to maintain and operate string values. This function modifies the string data as per function. We can do the concatenation, conversion, removal and replacing the...

4 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 DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

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

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.