MySQL Tutorial

MySQL Tutorial MySQL Features MySQL Database Introduction MySQL Environmental Setup MySQL Data Types MySQL variable MySQL Advance table Query MySQL database queries MySQL Entity-Relationship Model MySQL Table Query MySQL Operators MySQL logical conditions MySQL Queries MySQL Clauses Clustered vs Non-Clustered Index MySQL Full text index MySQL Descending Index MySQL Invisible Index MySQL Composite Index MySQL Prefix index MySQL Index MySQL Create index MySQL Drop Index MySQL Show index MySQL Unique index MySQL Table MySQL Variable MySQL View MySQL Constraints MySQL Command Line Client Basic Queries MySQL Stored Procedure MySQL IF Statement MySQL Subquery MySQL Triggers

MySQL Join

MySQL Join MySQL CROSS JOIN MySQL DELETE JOIN MySQL EQUI JOIN MySQL INNER JOIN MySQL Union MySQL NATURAL JOIN MySQL RIGHT JOIN MySQL SELF JOIN MySQL UPDATE JOIN

MySQL Function

MySQL Function MySQL AVG() Function MySQL SUM() Function MySQL String() Function MySQL Advance() Function MySQL Aggregate() Function MySQL COALESCE() Function MySQL Control Flow Function MySQL COUNT() Function MySQL Date And Time Function MySQL GREATEST() Function MySQL ISNULL() Function MySQL LEAST() Function MySQL Math() Function MySQL MAX() Function MySQL MIN() Function MySQL find_in_set() function MySQL ASIN() Function MySQL CEIL() function MySQL CEILING() function MySQL TAN() Function MySQL Truncate() Function MySQL FLOOR() function MySQL LN() function MySQL LOG2() function MySQL LOG10() function MySQL MOD() function MySQL PI() function MySQL POW() function MySQL RADIANS() function MySQL RAND() function MySQL ROUND() function MySQL Character Length Function MySQL Current Date Function MySQL Date Add Function MySQL Date Format Function MySQL Datediff Function MySQL Day Function MySQL Elt Function MySQL Export Set Function MySQL Field Function MySQL Format Function MySQL From Base64 Function MySQL Hex Function MySQL Insert Function MySQL Instr Function MySQL Length Function MySQL CONCAT() function MySQL FIND_IN_SET() function MySQL LIKE() function MySQL LOAD_FILE() function MySQL LOCATE() function MySQL LOG() function MySQL MONTHNAME() function MySQL NOW() function MySQL PERIOD_ADD() function MySQL PERIOD_DIFF() function MySQL POWER() function MySQL QUARTER() function MySQL REVERSE() function MySQL RIGHT() Function MySQL RPAD() function MySQL RTRIM() function MySQL SEC_TO_TIME() function MySQL SOUNDEX() function

Questions

Which Clause is Similar to Having Clause in MySQL

Misc

MySQL Error 1046 - No Database Selected Failed to Start MySQL Service Unit MySQL Service Unit not Found Import MySQL Connector Mudule not Found Error No Module Named MySQL Joins Available in MySQL MySQL Docs MySQL Download For Windows 7 64 Bit MySQL Error Code 1064 MySQL Export MySQL History MySQL Host MySQL Import MySQL Drop All Tables MySQL Drop MySQL Error Code 1175 MySQL Events MySQL Except MYSQL Foreign Key Constraint MySQL If Exists MySQL IndexOf MySQL List All Tables json_extract in MySQL

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.