SQL语句快速参考

来源:互联网 发布:数值最优化 高立 pdf 编辑:程序博客网 时间:2024/05/01 15:59

来自 W3CSchool 的 SQL 快速参考


SQL 语句语法AND / ORSELECT column_name(s)
FROM table_name
WHERE condition
AND|OR conditionALTER 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 value2CREATE DATABASECREATE DATABASE database_nameCREATE 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 conditionDELETEDELETE 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_nameDROP 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_nameGROUP BYSELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_nameHAVINGSELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator valueINSELECT 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_nameLEFT JOINSELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2 
ON table_name1.column_name=table_name2.column_nameRIGHT JOINSELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2 
ON table_name1.column_name=table_name2.column_nameFULL JOINSELECT column_name(s)
FROM table_name1
FULL JOIN table_name2 
ON table_name1.column_name=table_name2.column_nameLIKESELECT column_name(s)
FROM table_name
WHERE column_name LIKE patternORDER BYSELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC|DESC]SELECTSELECT column_name(s)
FROM table_nameSELECT *SELECT *
FROM table_nameSELECT DISTINCTSELECT DISTINCT column_name(s)
FROM table_nameSELECT 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_nameTRUNCATE TABLETRUNCATE TABLE table_nameUNIONSELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2UNION ALLSELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2UPDATEUPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_valueWHERESELECT column_name(s)
FROM table_name
WHERE column_name operator value

来源:http://www.w3cschool.cc/sql/sql-quickref.html

0 0
原创粉丝点击