简体   繁体   中英

SQL SERVER, will select query with (TABLOCKX) faster than with(NOLOCK) or vice versa?

I had question above question. We are using with nolock through out the application. In some cases I need to work select faster, what ever the effect.

So select with(TABLOCKX) will be faster or with(nolock) ?

To answer your question, the with (nolock) table hint will be faster.

NOLOCK typically (depending on your DB engine) means give me your data, and I don't care what state it is in, and don't bother holding it still while you read from it. It is all at once faster, less resource-intensive, and very very dangerous.

As explained very well here NoLock

Nolock means you can read some locked rows (with shared locks). But you still have to wait on other locks.

Tablockx means you block whole table with exclusive lock for other queries - other session cannot make locks, you cannot be blocked after you block whole table. Tablockx is mostly used for rapid inserts.

Avoid using nolock everywhere. Try to avoid exclusive locks for longer times or try minimalize your blocking and then you don't need nolocks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM