×

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 Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.

MySQL Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL ISNULL function

This function is used to check the null value in table data. It returns the result in a Boolean form. If table data is null, then the output becomes 1....

2 minutes read.

MySQL EXPORT_SET() function

In this context, we will learn how we can use the MySQL EXPORT_SET() function with proper syntax and good examples. Introduction of MySQL EXPORT_SET() function This function returns a string and shows...

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

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 minutes read.

MySQL FROM_BASE64() function

In this context, we will learn how we can use the MySQL FROM_BASE64()() function with proper syntax and good examples. Introduction of MySQL FROM_BASE64()() function Basically, the FROM_BASE64() function In MySQL decodes...

2 minutes read.

Clustered vs Non-Clustered Index

Clustered vs. Non-Clustered Index The difference between clustered and non-clustered index is the most famous question in the database-related interviews. Both indexes have the same physical structure and are stored as...

2 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 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 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 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 UPDATE JOIN

The UPDATE JOIN is a MySQL statement used to perform cross-table updates that means we can update one table using another table with the JOIN clause condition. The "update join"...

5 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

MySQL IF statement

The IF statement shows the true condition of the control flow function. The first condition is necessary to fulfill the requirement. The other condition is optional in the "IF" statement....

3 minutes read.

MySQL FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 minutes read.

MySQL RADIANS() function

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

2 minutes read.

MySQL COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

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.