I used to see my senior developers use WITH (NOLOCK) when querying in SQL Server and wonder why they use. Now i explored it and found that it‘s useful to improve the performance in executing the query . However there is a disadvantage in using it. The disadvantage is that one may not be sure that they are getting the data which is currently being updated in the Table, ie, Without lock protection, you cannot be guaranteed that the data isn‘t changing during the time that the query is running. I referred this link and found it pretty useful.
要提升SQL的查询效能,一般来说大家会以建立索引(index)为第一考虑。其实除了index的建立之外,当我们在下SQL Command时,在语法中加一段WITH (NOLOCK)可以改善在线大量查询的环境中数据集被LOCK的现象藉此改善查询的效能。
不过有一点千万要注意的就是,WITH (NOLOCK)的SQL SELECT有可能会造成Dirty Read。
例如:
SELECT COUNT(UserID)
FROM EMPLOYEE WITH (NOLOCK)
JOIN WORKING_GROUP WITH (NOLOCK)
ON EMPLOYEE.UserID = WORKING_GROUP.UserID
sql SELECT时的with(nolock)选项说明,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/hyshareex/p/3809334.html