

We use the latest jdbc driver from Microsoft. We also use a POJO development model with Spring 2.0 that takes care of transaction demarcation (that plugs into Jboss's JTA).
Sql deadlock with nolock windows#
We use JDK 5 and Hibernate 3.2 (with annotions), our MS-SQL 2005 database runs (of course) on a windows machine, Our application runs on Jboss 4.0.4 on a Red-Hat Linux machine (but we also see the problems at our development boxes on windows). This is because there may be other tables that need to be updated which relate to the ‘derek’ record (id=1) in order to show a consistent view of all data related to ‘derek’.įinally let’s commit our transaction within our original window and you’ll see that you are now able to query the data without using (nolock).We just started to test our system with some modest users load and we are experiencing some critical database access related problems. The data that has been successfully read is considered dirty data. Here you will see the first query will show the updated value ‘derek’, whereas the query without the nolock will hang waiting for the transaction to release. Open a new connection and execute the following queries: Here we have left a transaction open on #my_name so that row is exclusively locked and cannot be read by any transaction using isolation level read committed or higher. IF OBJECT_ID(‘tempdb.#my_name’) IS NOT NULL
Sql deadlock with nolock update#
The following example will open a transaction in order to update the first_name column in our global temp table: #my_name The assumption here is that if your system uses explicit transactions or relies on triggers heavily, it may be plausible to assume nolock is not a good idea.ĭo not use WITH (NOLOCK) without fully understanding the ramifications of a dirty read Statements that query the changed data using the READ COMMITTED isolation level will be blocked from seeing these changes until commit, whereas READ UNCOMMITTED (NOLOCK) will see the changes immediately irregardless of when the commit occurs.

Multiple statements executed within a transaction experience a time delay of their INSERT / UPDATE / DELETE operations however the changes are committed at once upon the COMMIT. The biggest red flag I can think of for not using NOLOCK would be a system that uses explicit transactions (BEGIN TRAN. It is important to know where things could go wrong though. In most places I have worked, with (nolock) has been a generally accepted practice in the specific areas of the system that are not sensitive to data being slightly out of sync.


