xyjzsh

sqlserver2008里面的游标

 SQL是一种基于集合的语言(a set-based language) ,他更擅长操作和提出一组数据,而不是对
 数据进行一行一行的处理。
 SQL is a set-based language ,meaning that is excels at mantipulating and retrieving
 set of rows ,rather than performing single row-by-row processing.
 如果你的程序里一定要一条一条的执行,那么一定要先考虑使用如while循环,子查询,
 临时表,表变量等等,如果这些都不能满足要求,在考虑使用游标。
 
 T-SQL中游标的生存周期:
 1.用返回一个有效结果集的sql语句来定义一个游标。
  a cursor is defined via a SQL statement that returns a valid result set.
 2. 打开游标
 3. 一旦游标被打开就可以从游标中每次取出一行数据,要根据游标的定义可以向前去数据或
 向后取数据
 the rows can be fetched moving forword or backword ,depending on the original cursor definition.
 4. 根据游标的类型,数据可以被修改或者只能读。
 5.最后,用完游标后,必须被显示的关闭,并且从内存中移除。
 
 游标定义格式:
 declare cursor_name cursor
 [local|global]
 [forword_only|scroll]
 [static|keyset|dynamic|fast_forword]
 [read_only| scroll_locks|optimistic]
 [type_warning]
 for select_statement[for update [of column[,...]]]
 
The select_statement argument is the query used to define the data within the cursor. Avoid
using a query that hasmore columns and rows than will actually be used, because cursors, while
open, are kept inmemory. The UPDATE [OF column_name [,...n]] is used to specify those columns
that are allowed to be updated by the cursor.
 

posted on 2011-11-03 16:28 呆人 阅读(1651) 评论(0)  编辑 收藏 引用 所属分类: sqlserver2008


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜