> At my old employer, one the developers swore by using the
> term "with nolock" in all of his SQL queries, I understand
> that this bypasses SQL Servers automatic record locking and
> it does improve speed.
>
> But this practice sets off alarms in my head, because it just
> seems like a bad thing to do. Wouldn't this set up race conditions
> on the SQL Server?
While I wouldn't characterize using table hints like NOLOCK as a "bad thing
to do", it isn't something you want to without careful thought. By bypassing
record locking, you're creating the possibility of selecting bad data -
records that no longer exist (phantom records), or records that are in the
process of being changed at that instant ("dirty" records).
In some limited cases, you just might not care that you're getting the
correct data. For example, let's say you're trying to figure out the average
price for all the products in a shopping cart. That's an aggregate value,
and if you have several hundred thousand products, one incorrect value won't
throw off your calculation by a significant amount.
But in most cases, you wouldn't want to bypass record locking, since that's
the whole point of using a relational database - it ensures data integrity.
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:225253
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54