SQL 快速参考

来自 W3School 的 SQL 快速参考。可以打印它,以备日常使用。

SQL 语句

语句语法
AND / ORSELECT 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
BETWEENSELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
CREATE DATABASECREATE DATABASE database_name
CREATE INDEXCREATE INDEX index_name
ON table_name (column_name)
CREATE TABLECREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
.......
)
CREATE UNIQUE INDEXCREATE UNIQUE INDEX index_name
ON table_name (column_name)
CREATE VIEWCREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
DELETE FROMDELETE FROM table_name
(Note: Deletes the entire table!!)

or

DELETE FROM table_name
WHERE condition

DROP DATABASEDROP DATABASE database_name
DROP INDEXDROP INDEX table_name.index_name
DROP TABLEDROP TABLE table_name
GROUP BYSELECT column_name1,SUM(column_name2)
FROM table_name
GROUP BY column_name1
HAVINGSELECT column_name1,SUM(column_name2)
FROM table_name
GROUP BY column_name1
HAVING SUM(column_name2) condition value
INSELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
INSERT INTOINSERT INTO table_name
VALUES (value1, value2,....)

or

INSERT INTO table_name
(column_name1, column_name2,...)
VALUES (value1, value2,....)

LIKESELECT column_name(s)
FROM table_name
WHERE column_name
LIKE pattern
ORDER BYSELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC|DESC]
SELECTSELECT column_name(s)
FROM table_name
SELECT *SELECT *
FROM table_name
SELECT DISTINCTSELECT 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
UPDATEUPDATE table_name
SET column_name=new_value
[, column_name=new_value]
WHERE column_name=some_value
WHERESELECT column_name(s)
FROM table_name
WHERE condition
推荐阅读:
php 读取和设置redis的键值   阅读:8089网站局部小图片优化-base64编码图片   阅读:20778一键分享到QQ空间、QQ好友、新浪微博、微信代码   阅读:135971javascript点击复制内容   阅读:7902shell发送邮件脚本   阅读:9761nginx安装mysql和json模块   阅读:6432nginx安装mysql和json模块   阅读:6432给php7安装redis扩展库   阅读:9167给 centos 7 安装桌面环境   阅读:17800封装php redis缓存操作类   阅读:10165面试的时候回去等通知,等电话的真实意思   阅读:25919centos 7 忘记root密码   阅读:5604php打印九九乘法表   阅读:12248nginx安装redis模块   阅读:7192php 获取当前前后年、月、星期、日、时分秒的时间   阅读:7580centos 7 安装 samba 服务   阅读:7634php文件下载防盗链   阅读:10779shell脚本批量删除几天前的文件   阅读:11442mysql5.7开启sql日志的配置   阅读:10457简单的DOS攻击之死亡之ping详解   阅读:67206php压缩页面的html代码一行显示   阅读:8449最简单的Banner轮播左右切换效果代码及实现思路(附带源码)   阅读:33832最新centos7 搭建LNMP环境(centos7.2+php7+mysql5.7+nginx1.11+redis3.2)   阅读:11926linux时间戳有趣的情人节秒1234567890   阅读:6173HTTP 1.1 协议详解   阅读:14917php文件下载防盗链   阅读:10779centos 7 添加 redis 3.2.9 开机启动脚本   阅读:10362十张GIF让你弄懂递归等概念   阅读:6903分享:淘宝技术这十年   阅读:5315csv文件一键导入数据到mysql数据库   阅读:7525linux php7编译安装mongodb扩展   阅读:9908最简单的Banner轮播淡入淡出效果代码及实现思路(附带源码)   阅读:14535给网站添加一键qq登录的功能   阅读:8356网站性能优化-页面静态缓存   阅读:6118mysql数据库性能的基本优化   阅读:5077分享:淘宝技术这十年   阅读:5315centos7开启交换内存   阅读:12123给网站添加一键新浪微博登录的功能   阅读:7171centos 7 安装 php-7.1.3   阅读:21826centos7开启交换内存   阅读:12123centos 7 忘记root密码   阅读:5604人性漫画:打工与创业的残酷区别   阅读:5628centos 7 安装 nginx-1.11.10   阅读:9378给网站添加一键新浪微博登录的功能   阅读:7171linux php7安装yaf扩展   阅读:9490十张GIF让你弄懂递归等概念   阅读:6903nginx编译安装后对nginx进行平滑升级   阅读:7534linux php7安装yaf扩展   阅读:9490知乎百万赞作者告诉你:年薪百万的人都在靠什么赚钱   阅读:7622php压缩页面的html代码一行显示   阅读:8449