Sql-重点
2009-10-05 16:06
267 查看
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'
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'
相关文章推荐
- SQL:查找被锁的表,以及锁表的SQL语句(重点推荐)
- SQL语句优化--重点
- Oracle中存储过程和Sql语句的优化重点
- SQL中 where, group by,having,order by 的重点
- Spark SQL重点
- Hibernate 原生sql 划重点
- 举例详解—标准SQL的9种语句(重点之三)
- DB2 sql 重点难点复习总结
- SQL中的集合运算符实例(重点)
- SQL学习重点概述
- Oracle经典sql语句总结@sql-plus重点函数串讲与sql语句案例@中文排序详讲).doc
- Oracle中存储过程和Sql语句的优化重点
- PL/SQL编程重点语句输出整理
- 0724工作小结 SQL查库是重点
- Oracle经典sql语句总结@sql-plus重点函数串讲与sql语句案例@中文排序详讲).doc
- Microsoft SQL Server 2012 管理 (1): 安装配置SQL Server 重点
- SQL:查找被锁的表,以及锁表的SQL语句(重点推荐)
- SQL语句优化-重点在于使用到索引
- SQL优化是重点
- SQL指令总结(重点之一)