是否有任何其他选项,而不是在SQL Server中使用游标 [英] Is there any other option instead of using cursor in sql server

查看:101
本文介绍了是否有任何其他选项,而不是在SQL Server中使用游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Plz建议我是否有任何其他选项而不是游标..我有使用游标的存储过程但是在线服务器上运行需要很长时间..所以如果有任何其他选项我可以使用光标的地方PLZ告诉我..

提前感谢..

Plz suggest me if there is any other option instead of cursor.. I have store procedure in which I use cursor but it takes long time to run on online server.. So if there is any other option that I can use in place of cursor plz tell me..
thanks in advance..

推荐答案

嗨Heta,



请在下面找到示例。





我们可以使用临时表而不是游标。





Hi Heta,

Please find below example.


We can use Temporary tables instead of Cursors.


DECLARE @MaxCount INT
DECLARE @Count INT
SET @Count =1







CREATE TABLE  #TempTable
(  
Id INT  Identity(1,1),  
KeyWord VARCHAR(100)  
)  




SELECT @MaxCount =MAX(ID) FROM #TempTable



WHILE (@Count < = @MaxCount)
BEGIN



-- Do some operation 

SET @Count= @Count+1;


END


过去,我有回答了类似的问题,查看替代品

光标替代品 [ ^ ]
In past, I have answered similar question, check it out alternatives
Cursor alternatives[^]


这篇关于是否有任何其他选项,而不是在SQL Server中使用游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆