SQL 1 : SQL 教程 2 : SQL 简介 3 : SQL 语法 4 : SQL SELECT 语句 5 : SQL SELECT DISTINCT 6 : SQL WHERE 子句 7 : SQL AND & OR 运算符 8 : SQL ORDER BY 关键字 9 : SQL INSERT INTO 10 : SQL UPDATE 语句 11 : SQL DELETE 语句 12 : SQL SELECT TOP, LIMIT, ROWNUM 13 : SQL LIKE 操作符 14 : SQL 通配符 15 : SQL IN 操作符 16 : SQL BETWEEN 操作符 17 : SQL 别名 18 : SQL 连接(JOIN) 19 : SQL INNER JOIN 关键字 20 : SQL LEFT JOIN 关键字 21 : SQL RIGHT JOIN 关键字 22 : SQL FULL OUTER JOIN 23 : SQL UNION 操作符 24 : SQL SELECT INTO 25 : SQL INSERT INTO SELECT 26 : SQL CREATE DATABASE 27 : SQL CREATE TABLE 28 : SQL 约束 29 : SQL NOT NULL 约束 30 : SQL UNIQUE 约束 31 : SQL PRIMARY KEY 32 : SQL FOREIGN KEY 33 : SQL CHECK 约束 34 : SQL DEFAULT 约束 35 : SQL CREATE INDEX 36 : SQL 撤销索引、表以及数据库 37 : SQL ALTER TABLE 38 : SQL AUTO INCREMENT 39 : SQL 视图 (Views) 40 : SQL Server 和 MySQL 中的 Date 函数 41 : SQL NULL 值 – IS NULL 和 IS NOT NULL 42 : SQL ISNULL()、NVL()、IFNULL() 和 COALESCE() 函数 43 : SQL 通用数据类型 44 : SQL MS Access、MySQL 和 SQL Server 数据类型 45 : SQL 函数 46 : SQL AVG() 函数 47 : SQL COUNT() 函数 48 : SQL FIRST() 函数 49 : SQL LAST() 函数 50 : SQL MAX() 函数 51 : SQL MIN() 函数 52 : SQL SUM() 函数 53 : SQL GROUP BY 语句 54 : SQL HAVING 子句 55 : SQL UCASE() 函数 56 : SQL LCASE() 函数 57 : SQL MID() 函数 58 : SQL LEN() 函数 59 : SQL ROUND() 函数 60 : SQL NOW() 函数 61 : SQL FORMAT() 函数 62 : SQL 快速参考 63 : SQL 主机 64 : SQL 总结

SQL 快速参考


SQL 语句语法
AND / ORSELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
ALTER TABLEALTER TABLE table_name
ADD column_name datatype

or

ALTER TABLE table_name
DROP COLUMN column_name

AS (alias)SELECT column_name AS column_alias
FROM table_name

or

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 TABLECREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name2 data_type,
...
)
CREATE INDEXCREATE INDEX index_name
ON table_name (column_name)

or

CREATE UNIQUE INDEX index_name
ON table_name (column_name)

CREATE VIEWCREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
DELETEDELETE FROM table_name
WHERE some_column=some_value

or

DELETE FROM table_name
(Note: Deletes the entire table!!)

DELETE * FROM table_name
(Note: Deletes the entire table!!)

DROP DATABASEDROP DATABASE database_name
DROP INDEXDROP 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_name
DROP INDEX index_name (MySQL)
DROP TABLEDROP TABLE table_name
GROUP BYSELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVINGSELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
INSELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
INSERT INTOINSERT INTO table_name
VALUES (value1, value2, value3,....)

or

INSERT INTO table_name
(column1, column2, column3,...)
VALUES (value1, value2, value3,....)

INNER JOINSELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
LEFT JOINSELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
RIGHT JOINSELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
FULL JOINSELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
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 INTOSELECT *
INTO new_table_name [IN externaldatabase]
FROM old_table_name

or

SELECT column_name(s)
INTO new_table_name [IN externaldatabase]
FROM old_table_name

SELECT TOPSELECT TOP number|percent column_name(s)
FROM table_name
TRUNCATE TABLETRUNCATE TABLE table_name
UNIONSELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
UNION ALLSELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
UPDATEUPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value
WHERESELECT column_name(s)
FROM table_name
WHERE column_name operator value
关注极客云图了解更多内容