SQL语句快速参考手册

SQL 语句快速参考手册

这个是从w3c抄来的,我加了个备注。注意!!!这个是sql的标准,不是mysql的,所以虽然大部分都是通用的,但是个别语句是有区分的

SQL 语句 语法 备注
AND / OR SELECT column_name(s)FROM table_nameWHERE conditionAND|OR condition 且/或
ALTER TABLE ALTER TABLE table_name ADD column_name datatypeorALTER TABLE table_name DROP COLUMN column_name 改表
AS (alias) SELECT column_name AS column_aliasFROM table_nameorSELECT column_nameFROM table_name AS table_alias 别名
BETWEEN SELECT column_name(s)FROM table_nameWHERE column_nameBETWEEN value1 AND value2 范围
CREATE DATABASE CREATE DATABASE database_name 创建库
CREATE TABLE CREATE TABLE table_name(column_name1 data_type,column_name2 data_type,column_name2 data_type,...) 创建表
CREATE INDEX CREATE INDEX index_nameON table_name (column_name)orCREATE UNIQUE INDEX index_nameON table_name (column_name) 创建索引
CREATE VIEW CREATE VIEW view_name ASSELECT column_name(s)FROM table_nameWHERE condition 创建视图
DELETE DELETE FROM table_nameWHERE some_column=some_valueorDELETE FROM table_name (Note: Deletes the entire table!!)DELETE * FROM table_name (Note: Deletes the entire table!!) 删除数据
DROP DATABASE DROP DATABASE database_name 删除库
DROP INDEX DROP INDEX table_name.index_name (SQL Server)DROP INDEX index_name ON table_name (MS Access)DROP INDEX index_name (DB2/Oracle)ALTER TABLE table_nameDROP INDEX index_name (MySQL) 删除索引
DROP TABLE DROP TABLE table_name 删除表
GROUP BY SELECT column_name, aggregate_function(column_name)FROM table_nameWHERE column_name operator valueGROUP BY column_name 分组
HAVING SELECT column_name, aggregate_function(column_name)FROM table_nameWHERE column_name operator valueGROUP BY column_nameHAVING aggregate_function(column_name) operator value 过滤分组数据的
IN SELECT column_name(s)FROM table_nameWHERE column_nameIN (value1,value2,..) 范围内
INSERT INTO INSERT INTO table_nameVALUES (value1, value2, value3,....)orINSERT INTO table_name(column1, column2, column3,...)VALUES (value1, value2, value3,....) 添加
INNER JOIN SELECT column_name(s)FROM table_name1INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name 内连接
LEFT JOIN SELECT column_name(s)FROM table_name1LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name 左联接
RIGHT JOIN SELECT column_name(s)FROM table_name1RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name 右连接
FULL JOIN SELECT column_name(s)FROM table_name1FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name 全连接
LIKE SELECT column_name(s)FROM table_nameWHERE column_nameLIKE pattern 模糊
ORDER BY SELECT column_name(s)FROM table_nameORDER 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 SELECT INTO new_table_name [IN externaldatabase]FROM old_table_nameor*SELECT column_name(s)INTO new_table_name [IN externaldatabase]FROM old_table_name 查询旧表插入新表
SELECT TOP SELECT TOP number|percent column_name(s)FROM table_name =mysql的limit
TRUNCATE TABLE TRUNCATE TABLE table_name 清除表数据
UNION SELECT column_name(s) FROM table_name1UNIONSELECT column_name(s) FROM table_name2 合并查询
UNION ALL SELECT column_name(s) FROM table_name1UNION ALLSELECT column_name(s) FROM table_name2 全合并
UPDATE UPDATE table_nameSET column1=value, column2=value,...WHERE some_column=some_value 更新数据
WHERE SELECT column_name(s)FROM table_nameWHERE column_name operator value 条件查询

About This Page

Made with bootstrap and jquery by TaoYuan.

Contact Me

Click! If you are interested