数据库 DATABASE:
创建
CREATTE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [DEFAULT] CHARACTER SET [=] charset_name 。
删除:
DROP {DATABASE | SCHEMA} [IF EXISTS] db_name;
显示:
SHOW{ DATABASES| SCHEMAS} [LIKE ‘pattern‘|WHERE expr];
选择:
USE database_name ;
数据表 TABLE :
创建:
CREATE TABLE [IF NOT EXISTS] table_name( column_name data_type, ...) //()内为库里面每一列的名称
删除:
DROP TABLE [IF EXISTS] table_name;
显示:
SHOW TABLES [ FROM db_name] [ LIKE ‘pattern‘||EHERE expr];
列 COLUMN:
加入:
ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST|AFTER col_name]
//FIRST 加入到最前端, AFTER col_name ,跟在col_name 后边,省略该项,则加在最后面。
删除:
ALTER TABLE tbl_name DROP [COLUMN] col_name;
记录 ROW:
加入:
INSERT [INTO]tbl_name [(col_name,...)] VALUES(val,..)
删除:
DELETE FROM tbl_name [WHERE where_condition]
改动/更新:
UPDATA[LOW_PRIORITY][IGNORE ] table_reference SET col_name1={expr1|DEFAULT} [,col_name2={expr2|DEFAULT}]...
[WHERE where_condition]
样例: UPDATE users SET age=18 WHERE age=17;
显示:
SELECT expr, ...FROM tal_name;
SELECT * FROM tal_name; //查看全部
查询:
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 offset}]
]
//比如: SELECT name FROM users WHERE id=3;
其它:
约束条件:NOT NULL ; PRIMARY KEY; UNIQUE KEY; DEFAULT; FOREIGN KEY
其它经常使用keyword:AUTO_INCREMENT