Basic MySql operation statements
DATABASE:Create
CREATTE {DATABASE | SCHEMA} [if not exists] db_name [DEFAULT] character set [=] charset_name;
Delete:
DROP {DATABASE | SCHEMA} [if exists] db_name;
Display:
SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr];
Select:
USE database_name;
TABLE:Create:
Create table [if not exists] table_name (column_name data_type,...) // the name of each column in the database
Delete:
Drop table [if exists] table_name;
Display:
Show tables [FROM db_name] [LIKE 'pattern' | EHERE expr];
COLUMN:Add:
Alter table tbl_name ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name]
// Add FIRST to the frontend, AFTER col_name, AFTER col_name. If this item is omitted, add it to the end;
Delete:
Alter table tbl_name DROP [COLUMN] col_name;
Record ROW:Add:
INSERT [INTO] tbl_name [(col_name,...)] VALUES (val ,..)
Delete:
Delete from tbl_name [WHERE where_condition]
Modify/update:
UPDATA [LOW_PRIORITY] [IGNORE] table_reference SET col_name1 = {expr1 | DEFAULT} [, col_name2 = {expr2 | DEFAULT}]...
[WHERE where_condition]
Example: UPDATE users SET age = 18 WHERE age = 17;
Display:
SELECT expr,... FROM tal_name;
SELECT * FROM tal_name; // view all
Query:
SELECT select_expr [, select_expr...]
[
FROM table_references
[WHERE where_condition]
[Group by {col_name | position} [ASC | DESC],...]
[HAVING where_condition]
[Order by {col_name | expr | position} [ASC | DESC],...]
[LIMIT {[offset,] row_count | row_count OFFSET}]
]
// Example: SELECT name FROM users WHERE id = 3;
Others:
Constraints:Not null; primary key; unique key; DEFAULT; FOREIGN KEY
Other common keywords: AUTO_INCREMENT