码迷,mamicode.com
首页 > 数据库 > 详细

部分SQLServer内容

时间:2017-06-14 20:07:41      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:except   nio   grant   span   删除   update   intersect   server   通过   

SQL分类:

  DDL  数据定义语言  CREATE  ALTER  DROP  DECLARE

  DML  数据操纵语言  SELECT  DELETE  UPDATE  INSERT

  DCL  数据控制语言  GRANT  REVOKE  COMMIT  ROLLBACK

 

索引的创建和删除    注:索引是不可更改的,想更改必须删除重新建

  create [unique] index idxname on tabname(col….)

  drop index idxname

视图的创建和删除

  create view viewname as select statement

  drop view viewname

like

  select * from table1 where field1 like ’%value1%’

排序、总数、求和、平均、最大、最小

  select * from table1 order by field1,field2 [desc]

  select count * as totalcount from table1

  select sum(field1) as sumvalue from table1

  select avg(field1) as avgvalue from table1

  select max(field1) as maxvalue from table1

  select min(field1) as maxvalue from table1

 

运算符

UNION   通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表      组合table1和table2

UNION  ALL   不消除重复行

EXCEPT  通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表        在table1中不在table2中

EXCEPT  ALL  不消除重复行

INTERSECT  通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表           在table1也在table2中

INTERSECT  ALL  不消除重复行

外链接

  左外连接   左连接  left outer join    结果集既包括连接表的匹配行,也包括左连接表的所有行    

    select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUTER JOIN b ON a.a = b.c

  右外连接  右连接  right outer join  结果集既包括连接表的匹配连接行,也包括右连接表的所有行

    select a.a, a.b, a.c, b.c, b.d, b.f from a RIGHT OUTER JOIN b ON a.a = b.c

  全外连接  full outer join  不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录

    select a.a, a.b, a.c, b.c, b.d, b.f from a FULL OUTER JOIN b ON a.a = b.c

 

部分SQLServer内容

标签:except   nio   grant   span   删除   update   intersect   server   通过   

原文地址:http://www.cnblogs.com/GaoAnLee/p/7009805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!