Forming a query in MySQL
MySQL server is a open-source relational database management system which is a
major support for web based applications.
MySQL server is used for data operations like querying, sorting, filtering, grouping,
modifying and joining the tables.
Some of the commonly used MySQL queries, operators, and functions are as follows:
1. SHOW DATABASES
This displays information of all the existing databases in the server.
Output:
2. USE database_name
database_name : name of the database
This sets the database as the current database in the MySQL server.
To display the current database name which is set, use syntax
SELECT DATABASE();
3. DESCRIBE table_name
table_name : name of the table
This describes the columns of the table_name with respect to Field, Type, Null, Key,
Default, Extra.
4. SHOW TABLES
This shows all the tables in the selected database as a information.
5. SHOW CREATE TABLE table_name
table_name : name of the table
This shows the complete CREATE TABLE statement used by MySQL for creating the
table.
6. SELECT NOW()
A MySQL query mostly starts with SELECT statement.
This query shows the current date and time.
7. CREATE DATABASE database_name
database_name : name of the database
This statement creates a new database.
8. DROP DATABASE database_name
database_name : name of the database
This statement deletes the database.
9. CREATE TABLE table_name(column1, column2, column3..)
table_name : name of the table
column1 : name of first column
column2 : name of second column
column3 : name of third column
When the developer start building an application, he needs to create database tables.
This statement creates a new table with the given columns.
Example:
CREATE TABLE employee (
'id' INTEGER NOT NULL AUTO_INCREMENT,
'name' VARCHAR (30) NOT NULL,
'profile' VARCHAR (40) DEFAULT 'engineer',
PRIMARY KEY ('id')
);
10. DROP TABLE table_name
table_name : name of the table
This statement deletes the mentioned table.