1. declare @temp table
2. (
3. [id] int IDENTITY(1,1),
4. [Name] varchar(10)
5. )
6. declare @tempId int,@tempName varchar(10)
7.
8. insert into @temp values(‘a‘)
9. insert into @temp values(‘b‘)
10. insert into @temp values(‘c‘)
11. insert into @temp values(‘d‘)
12. insert into @temp values(‘e‘)
13.
14. --select * from @temp
15.
16. WHILE EXISTS(select [id] from @temp)
17. begin
18. SET ROWCOUNT 1
19. select @tempId = [id],@tempName=[Name] from @temp
20. SET ROWCOUNT 0
21. delete from @temp where [id] = @tempId
22.
23. print ‘Name:----‘+@tempName
24. end
SQL Server中如何实现遍历表的记录,布布扣,bubuko.com
原文:http://www.cnblogs.com/rongfengliang/p/3710367.html