What's the difference between using "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" and NOLOCK? Is one better than the other?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
They're the same thing, just scoped differently. NOLOCK is placed on a per table basis and
SET Transaction...
can be placed as a block.NOLOCK is a query hint and as such only applies to the specifc table within the query in which it is specified.
Setting the transaction isolation level applies to all code executed hence forth within the current connection or until it is explicitly modified.
To clarify, functionally the isoloation level at work is the same however the scope which is covered may not be.
They have the same effect, only one is used as a lock hint (nolock) and the other is used for a connection scope.
Be careful with either of those - dirty reads can be a very bad thing depending on your app. Reading the same record twice or missing a record because of page movement can be a very confusing thing to users...
See that answer from a few hours ago, to the question SQL Server SELECT statements causing blocking.
Quoting Remus Rusanu:
The other answers may help you as well.