开发者

Can I apply NOLOCK with a database-wide setting?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜