注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

民主与科学

独立之人格,自由之思想

 
 
 

日志

 
 

SQL 快速参考  

2013-10-04 19:52:30|  分类: 数据库 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
原文:http://www.w3school.com.cn/sql/sql_quickref.asp

来自 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
结束
  评论这张
 
阅读(612)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017