# Common basic operations for Structured Query Language in MySQL:
/* DDL (Data Definition Language) Data Definition Language */
# Create a database:
Create database 'database name' charset utf8;
# Delete a database:
Drop database 'database name ';
# Display all databases:
Show databases;
# Use a database
Use 'database name ';
# Determine the currently used database:
Select database ();
# Display the structure of a table in the database
Desc 'table name ';
# Display the statement for creating a table
Show create table 'table name ';
# Create a table:
Create table 'table name '(
'Column name' 'column description ',
'Column name' 'column description ',
'Column name' 'column description ');
# Tables with primary keys and auto-Increment
Create table 'table name '(
'Column name' 'column description' 'Primary key auto_increment,
'Column name' 'column description ',
'Column name' 'column description ');
# Delete a table:
Drop table 'table name ';
# Modify a table:
Alter table 'old table name' rename'new table name ';
# Add fields
Alter table 'table name' add column 'column name' 'column description ';
# Modifying Fields
Alter table 'table name' change 'old column name' new column description ';
# Delete a field
Alter table 'table name'drop column' column name ';
/* DML (Data Manipulation Language) Data operation Language */
# Data Entry
Insert into 'table name' ('field name, field name... ') values ('corresponding value, corresponding value ...');
Insert into 'table name' values ('corresponding value, corresponding value ...');
# Update data
Update 'table name 'set' field name' = 'field value', 'field name' = 'field value'... where 'field name' = 'field value ';
Update 'table name 'set' field name' = 'field value', 'field name' = 'field value '...;
# Delete data
Delete from 'table name ';
Delete from 'table name' where 'field name' = 'field value ';
/* DQL (Data Queries Language) Data Query Language */
# Query all
Select * from 'table name ';
# Query required
Select 'field name', 'field name'... from 'table name ';
# Alias Query
Select 'field name', concat ('field name', 'field name') [as] 'Alias 'from 'table name ';
# Where Query
Select * from 'table name' where 'field name' like "_' value '%"
# Aggregate Query
Select count (*) from 'table name'; # Number of query records
Select 'field name' from 'table name' order by 'field name' desc; # query in descending order
Select distinct 'field name' from 'table name' order by 'field name' asc; # duplicate query in ascending order
# Query groups
Select avg ('field name') from 'table name' group by 'field name ';
Select avg (field name) as 'Alias ', 'Alias' from 'field name 'group by' field name 'having' field name '> 0;
/* DCL (Data Control Language) Data Control Language */
/* Constraint */
# Primary key constraints
Alter table 'table name' add constraint primary key ('field name ');
# Unique constraints
Alter table 'table name' add constraint unique ('field name ');
# Foreign key constraints
Alter table 'table name' add constraint foreign key ('foreign key field name') references 'Primary table' ('Primary key field name ');