如何为所有表的存储过程 T-SQL 设置 NO LOCK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20620934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put NO LOCK for stored procedure T-SQL for all tables
提问by Sergey
I want that my tables will not be locked. Is it possible to set NO LOCK for all tables in the stored procedure. What is the best way if I have a lot of tables like this:
我希望我的桌子不会被锁定。是否可以为存储过程中的所有表设置 NO LOCK。如果我有很多这样的表,最好的方法是什么:
select * from t1
join t2 ..
join t3 .. with (nolock)
select * from t4
join t4 ..
join t5 etc...
with (nolock)
回答by Phil Sandler
You can set this at the query level:
您可以在查询级别进行设置:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
Like NOLOCK, this allows for dirty reads.
像 NOLOCK 一样,这允许脏读。
回答by Sergey
If dirty reads are a problem you may look into using 'Isolation level Snapshot': this creates a regular snapschot of your database and uses that for calculation. Downside is that this copy requires extra memory.
如果脏读是一个问题,您可以考虑使用“隔离级别快照”:这会创建数据库的常规快照并将其用于计算。缺点是这个副本需要额外的内存。