Sql-重点

1-select all/distinct top  n [percent]

 

2-select xxx into new Table where ...不能与COMPUTE同时用.

 

3-select * from emp where emp.name like 'j#_y%' escape '#'---指定#为转义字符,使统配符号转为普通符号

<----------->select * from emp where emp.name like 'j[_]y%'-------这个中括号可以使统配符变为普通符号.

 

4-group by x,x with cube

 

   会显示分组列所有可能的统计行.

 

  having 字句与where 字句的区别,作用对象不一样.

 

  where  是作用于表视图.

 

  having作用于分组结果(聚集函数)

 

  select DeptId,Count(*) from Emp where emp.salary>6000 group by DeptId having Count(*) >1

 

5-Compute子句

   select * from Employee order by EmployeeName compute sum(Age) by EmployeeName

 

  会给结果集添加统计行,注意Order by的必要性。

 

6-union(all)-行的合并

 

  不加all,则行合并后去掉重复行。

7-链接查询(列的合并)

 

   inner join

   left join

   right join

   full join

 

   cross join

 

8-字查询

  Exists()是外层查询需要满足子查询条件的记录。是代入子查询检查。

  因为外层查询优先执行,可能会缩小查询范围。

  Not Exists()

 

 而别的条件子查询,是先进行子查询,然后再进行外层查询。

 

9-insert into tb select xxxxx批量插入。记账使用。

 

10-自定义数据类型

 

 exec sp_addtype typename systype 'not null'

 exec sp_droptype typename

 

 11-游标

 

   注意关键字:Insensitive--利用临时表存储游标记录集.那么所做的更新操作将不会影响 基础表

   获取数据状态:

  @@FetchStatus:

  0--- 获取成功

  -1--获取失败

  -2--获取的记录已经不再是游标记录集合中的记录,因为并发访问.

 

 

 

 

 12-锁

独占:dml

共享:select

更新--当真正更新,转换为独占锁

 

13-设置数据库的选项

sp_dboption

sp_dboption 'dsname'---显示指定数据库的打开的数据库。

sp_dboption 'dsname','optionname','optionvalue'

 

14-constraint

field-level-constraint

 

constraint constraintName primary key--主键约束

constraint constraintName unique-----唯一约束

constraint constraintName foreign key reference primaryTable(fieldName)--外键约束

constraint constraintName check fieldName>5--检查约束

 

--table-level-constaint

constraint constraintName primary key([],[.....])

 

--空值约束

 

--默认值约束

constraint cname Default value for fieldName

 

15-数据库对象/规则/默认值

 

create rule ruleName as '@n >60'

 

sp_bindrule 'ruleName' ,'fieldName'

 

create defult dname as 1000

 

sp_binddefault 'dname','fieldName'

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值