本文介绍了报告存储过程中的 NOLOCK 提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些 SSRS 报告在处理大量数据时运行缓慢.

We have some SSRS reports which run slowly with large amounts of data.

我们想在报表的后端存储过程中做一些查询优化.

We thought to do some query optimization in backend stored procedures in the reports.

我的问题是,为了报告目的,在存储过程(仅在 select 语句中)添加 (nolock) 提示是否好?

My question is, is it good to add with (nolock) hints in stored procedures (only in select statements) for reporting purposes?

推荐答案

DB 锁当然很重要,可以确保您的事务中不会涉及脏"数据.不过,在某些情况下您可以安全地使用 NOLOCK.例如,如果您必须使用游标(最好避免,但有时是必要的),则可以将游标写入它,在 NOLOCK 条件下仅选取最少的关键字段,然后在循环内根据需要读取表(带锁)) 使用游标字段值,执行更改、提交并移动到下一个游标 rec 以获得下一组键(在 nolock 下).如果使用得当,这是一种资产.

DB Locks of course are important to ensure you aren't getting 'dirty' data involved in your transactions. Still, there are conditions where you can safely use NOLOCK. For instance, if you must use a cursor ( best avoided, but sometimes necessary ), the cursor can be written to it picks up just the minimal key fields, under NOLOCK conditions, then inside the loop you read the tables as needed ( with locks ) using the cursor field values, carry out your changes, commit, and move to the next cursor rec to get you next set of keys ( under nolock ). It's asset if used wisely.

这篇关于报告存储过程中的 NOLOCK 提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:22