문제

Is there a way to make WITH(NOLOCK) be applied on any SELECT statement run on a particular database?

도움이 되었습니까?

해결책

No but you can use the SNAPSHOT ISOLATION Database level on SQL Server 2005 and up, it should help a lot with deadlocks

SQL Server 2005 introduces extensions to the SQL-92 isolation levels with the introduction of the SNAPSHOT isolation level and an additional implementation of READ COMMITTED. The new READ_COMMITTED_SNAPSHOT isolation level can transparently replace READ COMMITTED for all transactions.

SNAPSHOT isolation specifies that data read within a transaction will never reflect changes made by other simultaneous transactions. The transaction uses the data row versions that exist when the transaction begins. No locks are placed on the data when it is read, so SNAPSHOT transactions do not block other transactions from writing data. Transactions that write data do not block snapshot transactions from reading data. You need to enable snapshot isolation by setting the ALLOW_SNAPSHOT_ISOLATION database option in order to use it.

The READ_COMMITTED_SNAPSHOT database option determines the behavior of the default READ COMMITTED isolation level when snapshot isolation is enabled in a database. If you do not explicitly specify READ_COMMITTED_SNAPSHOT ON, READ COMMITTED is applied to all implicit transactions. This produces the same behavior as setting READ_COMMITTED_SNAPSHOT OFF (the default). When READ_COMMITTED_SNAPSHOT OFF is in effect, the Database Engine uses shared locks to enforce the default isolation level. If you set the READ_COMMITTED_SNAPSHOT database option to ON, the database engine uses row versioning and snapshot isolation as the default, instead of using locks to protect the data.

다른 팁

Depends on your database. Some database engines allow you to default to dirty reads or similar behaviors.

Example, some MSSQL Server versions allow you to setup the database as snapshot isolation, which is described in SQLMenace's post.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top