Thursday, October 23, 2008

NOLOCK in SQL Server to improve performance

Sometimes it is good to use nolock in SQL Server queries, specially when your query is just reading the records. It does improve the performance of the system. The disadvantage is that one may not be sure that they are getting the data which is currently being updated in the Table i.e. Without lock protection, you cannot be guaranteed that the data isn’t changing during the time that the query is running.

The sytax for using NOLOCK is:

SELECT * from TblName
WITH (NOLOCK)
WHERE col1=col2

More reference on this:
http://blogs.neudesic.com/blogs/phil_scott/archive/2005/12/05/11.aspx

No comments:

About Us