游标中的static参数
以下测试用例将演示,使用static的游标和不使用的区别:
if object_id(N't_test',N'u') is not null
drop table t_test
go create table t_test(
cola int primary key,
colb char(20)) insert into t_test values(1,'a')
insert into t_test values(2,'b')
insert into t_test values(3,'c') go
if exists (SELECT OBJECT_ID FROM sys.triggers WHERE name = 'tg_test')
drop trigger tg_test
go create trigger tg_test on t_test
for update
as
declare @id int,@text char(20),@max int
select @id = cola,@text = colb from inserted
select @max = max(cola) from t_test
insert into t_test values(@max + 1,'new'+@text)
go --begin tran
--select * into #temp from t_test
declare cur_test cursor forward_only static read_only
for select * from t_test
declare @id int,@text char(20)
open cur_test
fetch next from cur_test into @id,@text while @@fetch_status=0
begin
update t_test set colb = @text where cola = @id
fetch next from cur_test into @id,@text
end
close cur_test
deallocate cur_test
--commit go select * from t_test
另外,我发现,如果不使用static参数,而直接将for select * from t_test 语句改为for select top 100 * from t_test,结果集也将是静态的,我猜测使用了top的的语句,也是将数据集的副本存入了tempdb数据库中。
当然,你可以不使用static参数,但直接提前生成一个#temp临时表,然后for select * from #temp来进行操作。
更多游标内容,可以参考此位博友的此篇文章:http://www.cnblogs.com/CareySon/archive/2011/11/01/2231381.html
游标中的static参数的更多相关文章
- [原创]java WEB学习笔记109:Spring学习---spring对JDBC的支持:使用 JdbcTemplate 查询数据库,简化 JDBC 模板查询,在 JDBC 模板中使用具名参数两种实现
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- C++中的static关键字的总结
C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. 1.面向过程设计中的st ...
- C#中方法的参数的四种类型
C#中方法的参数有四种类型: 1. 值参数类型 (不加任何修饰符,是默认的类型) 2. 引用型参数 (以ref 修饰符声明) 3. 输出型参数 (以out 修 ...
- (转)C++中的static关键字的总结
文章转自 http://www.cnblogs.com/BeyondAnyTime/archive/2012/06/08/2542315.html C++的static有两种用法:面向过程程序设计中的 ...
- c++中关于static关键字的问题
C++的static关键字C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. ...
- android中的layoutparams参数使用的简单总结
定义: 我们可以在Android的framework中的ViewGroup类里找到定义的类: public static class LayoutParams{...} 此类有如下注释: Layout ...
- struts2:JSP页面及Action中获取HTTP参数(parameter)的几种方式
本文演示了JSP中获取HTTP参数的几种方式,还有action中获取HTTP参数的几种方式. 1. 创建JSP页面(testParam.jsp) <%@ page language=" ...
- C# 中的可变参数方法(VarArgs)
首先需要明确一点:这里提到的可变参数方法,指的是具有 CallingConventions.VarArgs 调用约定的方法,而不是包含 params 参数的方法.可以通过MethodBase.Call ...
- Java中的可变参数以及foreach语句
Java中的可变参数的定义格式如下: 返回值类型 方法名称(类型 ... 参数名称){} foreach语句的格式如下: for ( 数据类型 变量名称 :数据名称){ ... } public ...
随机推荐
- 内存管理(memory allocation内存分配)
Memory management is the act of managing computer memory. The essential requirement of memory manage ...
- translate函数使用
SQL> select data,translate(data,'0123456789','##########') as num1, replace(translate(data,'01234 ...
- PL/SQL游标使用
游标是用来处理使用SELECT语句从数据库中检索到的多行记录的工具.借助游标的功能,数据库应用程序可以对一组记录逐个进行处理,每次处理一行. 游标是从数据表中提取出来的数据,以临时表的形式存放在内存中 ...
- BZOJ3036: 绿豆蛙的归宿&Wikioi2488:绿豆蛙的归宿
3036: 绿豆蛙的归宿 Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 108 Solved: 73[Submit][Status] Descript ...
- intellij idea 2016版破解方法
之前办法不能用了,现在最新方法,打开http://idea.lanyus.com,直接获取验证码即可
- lightoj1051 Good and Bad (dp)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1051 题目大意:给你一个字符串,只包含大写字母和‘?’,如果字符串中出现了连续三个以上 ...
- nopcommerce中文网
nopcommerce中文网 | nopcommerce是国外asp.net领域一个高质量的b2c开源项目,基于EntityFramework和MVC开发,交流QQ群:75272942 nopcomm ...
- Python切割nginx日志_小组_ThinkSAAS
Python切割nginx日志_小组_ThinkSAAS Python切割nginx日志
- ngnix 配置
#运行用户 user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 error_log /var/log ...
- C语言中数据类型转换的学习
1. 整型和枚举类型数据的转换 测试代码如下: #include <stdio.h> typedef enum _E_TYPE_T { E_TYPE_1 = -1, E_T ...