目录搜索
SQL 基础教程SQL 语法SQL SELECT 语句SQL SELECT DISTINCT 语句SQL WHERE 子句SQL AND & OR 运算符SQL ORDER BY 关键字SQL INSERT INTO 语句SQL UPDATE 语句SQL DELETE 语句SQL 函数SQL Date 函数SQL NULL 函数SQL 函数SQL AVG() 函数SQL COUNT() 函数SQL FIRST() 函数SQL LAST() 函数SQL MAX() 函数SQL MIN() FunctionSQL SUM() FunctionSQL GROUP BY 语句SQL HAVING 子句SQL UCASE() 函数SQL LCASE() 函数SQL MID() 函数SQL LEN() 函数SQL ROUND() 函数SQL NOW() 函数SQL FORMAT() 函数SQL 快速参考SQL 主机SQL 高级教程SQL SELECT TOP 子句SQL LIKE 操作符SQL 通配符SQL IN 操作符SQL BETWEEN 操作符SQL 别名(Aliases)SQL 连接(Joins)SQL INNER JOIN 关键字SQL LEFT JOIN 关键字SQL RIGHT JOIN 关键字SQL FULL OUTER JOIN 关键字SQL UNION 操作符SQL SELECT INTO 语句SQL INSERT INTO SELECT 语句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 视图(Views)MySQL NOW() 函数MySQL CURDATE() 函数MySQL CURTIME() 函数MySQL DATE() 函数MySQL EXTRACT() 函数MySQL DATE ADD() 函数MySQL DATE SUB() 函数MySQL DATEDIFF() 函数MySQL DATE FORMAT() 函数SQL Server GETDATE() 函数SQL Server DATEPART() 函数SQL Server DATEADD() 函数SQL Server DATEDIFF() 函数SQL Server CONVERT() 函数SQL NULL 值SQL 通用数据类型SQL 用于各种数据库的数据类型
文字

SQL 快速参考



SQL 语句 语法
AND / OR SELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
ALTER TABLE ALTER 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

BETWEEN SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN 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_name
ON table_name (column_name)

or

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 DELETE 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 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_name
DROP INDEX index_name (MySQL)
DROP TABLE DROP TABLE table_name
GROUP BY SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING SELECT 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
IN SELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
INSERT INTO INSERT INTO table_name
VALUES (value1, value2, value3,....)

or

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

INNER JOIN SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
LEFT JOIN SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
RIGHT JOIN SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
FULL JOIN SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
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 SELECT *
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 TOP SELECT TOP number|percent column_name(s)
FROM table_name
TRUNCATE TABLE TRUNCATE TABLE table_name
UNION SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
UNION ALL SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
UPDATE UPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value
WHERE SELECT column_name(s)
FROM table_name
WHERE column_name operator value



上一篇:下一篇: