SQL Server中如何实现遍历表的记录
declare @temp table
(
[id] int IDENTITY(1,1),
[Name] varchar(10)
)
declare @tempId int,@tempName varchar(10)
insert into @temp values('a')
insert into @temp values('b')
insert into @temp values('c')
insert into @temp values('d')
insert into @temp values('e')
select * from @temp
WHILE EXISTS(select [id] from @temp)
begin
SET ROWCOUNT 1
select @tempId = [id],@tempName=[Name] from @temp
SET ROWCOUNT 0
delete from @temp where [id] = @tempId
print 'Name:----'+@tempName
end 附上另外一种sql 测试代码:
declare @temp table (
[id] int IDENTITY(1,1),
[Name] varchar(10) )
declare @tempId int,@tempName varchar(10) ,@tempcount int
insert into @temp values('a')
insert into @temp values('b')
insert into @temp values('c')
insert into @temp values('d')
insert into @temp values('e')
set @tempcount=(select COUNT(*) from @temp);
set @tempId=0;
while (@tempId<=@tempcount )
begin
set @tempName=(select name from @temp where id=@tempId);
print 'the id is :'+str(@tempId) +' the name is : '+@tempName;
set @tempId=@tempId+1;
end
测试结果如下:
the id is : 1 the name is : a the id is : 2 the name is : b the id is : 3 the name is : c the id is : 4 the name is : d the id is : 5 the name is : e
SQL Server中如何实现遍历表的记录的更多相关文章
- 从SQL Server中清除msdb备份和恢复记录
正如我在前面的技巧“您的数据库上次恢复是什么时候呢?”中提到的,SQL Server使msdb数据库内系统表中的备份和恢复记录保持激活状态.没有正常的维护,这些系统表将变得很大,从而导致对于msdb数 ...
- 在SQL SERVER中根据某字段分隔符将记录分成多条记录
XT_RSGL_KQSZ_LS表结构如下图: CREATE TABLE XT_RSGL_KQSZ_LS( KQFW VARCHAR(400) ) 其中KQFW字段以分割符 , 隔开 INSERT I ...
- 转载: SQL Server中的索引
http://www.blogjava.net/wangdetian168/archive/2011/03/07/347192.html 1 SQL Server中的索引 索引是与表或视图关联的磁盘上 ...
- Sql Server中的表访问方式Table Scan, Index Scan, Index Seek
1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找满足条件的数据 通过row ...
- 转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek
0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Us ...
- SQL SERVER中的两种常见死锁及解决思路
在sql server中,死锁都与一种锁有关,那就是排它锁(x锁).由于在同一时间对同一个数据库资源只能有一个数据库进程可以拥有排它锁.因此,一旦多个进程都需要获取某个或者同一个数据库资源的排它访问权 ...
- SQL Server中SCAN 和SEEK的区别
SQL Server中SCAN 和SEEK的区别 SQL SERVER使用扫描(scan)和查找(seek)这两种算法从数据表和索引中读取数据.这两种算法构成了查询的基础,几乎无处不在.Scan会扫描 ...
- SQL Server中的三种Join方式
1.测试数据准备 参考:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek 这篇博客中的实验数据准备.这两篇博客使用了相同的实验数据. 2.SQ ...
- SQL Server中的执行引擎入门
简介 当查询优化器(Query Optimizer)将T-SQL语句解析后并从执行计划中选择最低消耗的执行计划后,具体的执行就会交由执行引擎(Execution Engine)来进行执行.本文旨在 ...
随机推荐
- 20170624xlVBA正则分割分类汇总
Sub RegExpSubtotal() '声明变量 Dim Regex As Object '正则对象 Dim Dic As Object '字典对象 Dim Key As String '关键字 ...
- android--------根据文件路径加载指定文件
Android根据指定的文件路径,加载该路径下指定文件格式(图片格式 png, gif,jpg jpeg)的文件相关信息的列表. 如图: public class MainActivity exten ...
- 蓝桥杯—ALGO-18 单词接龙(DFS)
问题描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母, 要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次) ,在两个单词相连时,其 ...
- 快速切题 poj1573
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10708 Accepted: 5192 Des ...
- Myeclipse快键键
------------------------------------MyEclipse 快捷键1(CTRL)-------------------------------------Ctrl+1 ...
- bzoj1083
题解: 简单最小生成树 代码: #include<bits/stdc++.h> using namespace std; #define y1 ____y1 ; int z[N],f[N] ...
- jdk1.6中bin目录下的工具及其作用
jdk的javaw.javac等的介绍java:在msdos终端窗口中执行.class文件,即解释执行.class文件.通常所说的jvm解释权.javaw:在java自己的窗口中执行.class文件而 ...
- Oracle Rman 增量备份与差异备份
一.增量与差异 关于Incremental增量备份级别: Oracle 9i 共有五种级别 0 1 2 3 4,0级最高-4级最低,0级是1级的基础以此类推. Oracle 10g官方文档明确指出增量 ...
- static 关键字介绍
大家都知道,我们可以基于一个类创建多个该类的对象,每个对象都拥有自己的成员,互相独立.然而在某些时候,我们更希望该类所有的对象共享同一个成员.此时就是 static 大显身手的时候了!! Java 中 ...
- IO文件相关操作
IO编程 IO 即Input/Output input stream 就是数据从外面(磁盘.网络)流进内存,output stream 就是数据从内存流到外面去. 通常cpu 和 内存的速度远远高于 ...