游标的最好方式是不用游标。
游标替代方案:
--Declare variables DECLARE @item_category_id INT Declare @X BIGINT Set @X = 0 --Declare a memory table DECLARE @item_table TABLE (item_category_id INT) INSERT INTO @item_table(item_category_id) SELECT object_id From master.sys.objects c1(NOLOCK) --WHILE @loop_counter > 0 AND @item_category_counter <= @loop_counter WHILE (SELECT COUNT(1) FROM @item_table) > 0 BEGIN SELECT TOP 1 @item_category_id = item_category_id FROM @item_table --处理 Set @X = @X + @item_category_id delete from @item_table where item_category_id = @item_category_id END PRINT @X
【版权声明】
本站部分内容来源于互联网,本站不拥有所有权,不承担相关法律责任。如果发现本站有侵权的内容,欢迎发送邮件至masing@13sy.com 举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
上一篇: sqlserver与CLR
下一篇: 合并复制同步控制