# SQL 快速参考
**来自 W3School 的 SQL 快速参考。可以打印它,以备日常使用。**
## SQL 语句
| 语句 | 语法 |
| --- | --- |
| AND / OR | SELECT column_name(s) FROM table_name WHERE condition AND|OR condition |
| ALTER TABLE (add column) | ALTER TABLE table_name ADD column_name datatype |
| ALTER TABLE (drop column) | ALTER TABLE table_name DROP COLUMN column_name |
| AS (alias for column) | SELECT column_name AS column_alias FROM table_name |
| AS (alias for table) | SELECT column_name FROM table_name AS table_alias |
| BETWEEN | SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2 |
| CREATE DATABASE | CREATE DATABASE database_name |
| CREATE INDEX | CREATE INDEX index_name ON table_name (column_name) |
| CREATE TABLE | CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, ....... ) |
| CREATE UNIQUE INDEX | CREATE UNIQUE INDEX index_name ON table_name (column_name) |
| CREATE VIEW | CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition |
| DELETE FROM | DELETE FROM table_name (**Note:** Deletes the entire table!!) _or_ DELETE FROM table_name WHERE condition |
| DROP DATABASE | DROP DATABASE database_name |
| DROP INDEX | DROP INDEX table_name.index_name |
| DROP TABLE | DROP TABLE table_name |
| GROUP BY | SELECT column_name1,SUM(column_name2) FROM table_name GROUP BY column_name1 |
| HAVING | SELECT column_name1,SUM(column_name2) FROM table_name GROUP BY column_name1 HAVING SUM(column_name2) condition value |
| IN | SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,..) |
| INSERT INTO | INSERT INTO table_name VALUES (value1, value2,....) _or_ INSERT INTO table_name (column_name1, column_name2,...) VALUES (value1, value2,....) |
| LIKE | SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern |
| ORDER BY | SELECT column_name(s) FROM table_name ORDER BY column_name [ASC|DESC] |
| SELECT | SELECT column_name(s) FROM table_name |
| SELECT \* | SELECT \* FROM table_name |
| SELECT DISTINCT | SELECT DISTINCT column_name(s) FROM table_name |
| SELECT INTO (used to create backup copies of tables) | SELECT * INTO new_table_name FROM original_table_name _or_ SELECT column_name(s) INTO new_table_name FROM original_table_name |
| TRUNCATE TABLE (deletes only the data inside the table) | TRUNCATE TABLE table_name |
| UPDATE | UPDATE table_name SET column_name=new_value [, column_name=new_value] WHERE column_name=some_value |
| WHERE | SELECT column_name(s) FROM table_name WHERE condition |
- SQL基础
- SQL 简介
- SQL 语法
- SQL SELECT 语句
- SQL SELECT DISTINCT 语句
- SQL WHERE 子句
- SQL AND & OR 运算符
- SQL ORDER BY 子句
- SQL INSERT INTO 语句
- SQL UPDATE 语句
- SQL DELETE 语句
- SQL高级
- SQL TOP 子句
- SQL LIKE 操作符
- SQL 通配符
- SQL IN 操作符
- SQL BETWEEN 操作符
- SQL Alias(别名)
- SQL JOIN
- SQL INNER JOIN 关键字
- SQL LEFT JOIN 关键字
- SQL RIGHT JOIN 关键字
- SQL FULL JOIN 关键字
- SQL UNION 和 UNION ALL 操作符
- SQL SELECT INTO 语句
- SQL CREATE DATABASE 语句
- SQL CREATE TABLE 语句
- SQL 约束 (Constraints)
- SQL NOT NULL 约束
- SQL UNIQUE 约束
- SQL PRIMARY KEY 约束
- SQL FOREIGN KEY 约束
- SQL CHECK 约束
- SQL DEFAULT 约束
- SQL CREATE INDEX 语句
- SQL 撤销索引、表以及数据库
- SQL ALTER TABLE 语句
- SQL AUTO INCREMENT 字段
- SQL VIEW(视图)
- SQL函数
- SQL Date 函数
- SQL NULL 值
- SQL NULL 函数
- SQL 数据类型
- SQL 服务器 - RDBMS
- SQL 函数
- SQL AVG 函数
- SQL COUNT() 函数
- SQL FIRST() 函数
- SQL LAST() 函数
- SQL MAX() 函数
- SQL MIN() 函数
- SQL SUM() 函数
- SQL GROUP BY 语句
- SQL HAVING 子句
- SQL UCASE() 函数
- SQL LCASE() 函数
- SQL MID() 函数
- SQL LEN() 函数
- SQL ROUND() 函数
- SQL NOW() 函数
- SQL FORMAT() 函数
- SQL 快速参考
- SQLite 基础
- SQLite 简介
- SQLite 安装
- SQLite 命令
- SQLite 语法
- SQLite 数据类型
- SQLite 创建数据库
- SQLite 附加数据库
- SQLite 分离数据库
- SQLite 创建表
- SQLite 删除表
- SQLite Insert 语句
- SQLite Select 语句
- SQLite 运算符
- SQLite 表达式
- SQLite Where 子句
- SQLite AND/OR 运算符
- SQLite Update 语句
- SQLite Delete 语句
- SQLite Like 子句
- SQLite Glob 子句
- SQLite Limit 子句
- SQLite Order By
- SQLite Group By
- SQLite Having 子句
- SQLite Distinct 关键字
- SQLite 高级
- SQLite PRAGMA
- SQLite 约束
- SQLite Joins
- SQLite Unions 子句
- SQLite NULL 值
- SQLite 别名
- SQLite 触发器(Trigger)
- SQLite 索引(Index)
- SQLite Indexed By
- SQLite Alter 命令
- SQLite Truncate Table
- SQLite 视图(View)
- SQLite 事务(Transaction)
- SQLite 子查询
- SQLite Autoincrement(自动递增)
- SQLite 注入
- SQLite Explain(解释)
- SQLite Vacuum
- SQLite 日期 & 时间
- SQLite 常用函数
- SQLite 接口
- SQLite - C/C++
- SQLite - Java
- SQLite - PHP
- SQLite - Perl
- SQLite - Python
- MySQL 教程
- MySQL 教程
- MySQL 安装
- MySQL 管理
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- MySQL 排序
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- MySQL 元数据
- MySQL 序列使用
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- 免责声明