Given the following statement on the AdventureWorks database:
UPDATE Sales.SalesOrderDetail SET OrderQty = 100 WHERE ModifiedDate >= '2014-01-01'
If I open another query window and look at the locks the query is using by running
sp_WhoIsActive @get_locks =1
i can see locks as follows:
<Object name="Person" schema_name="Person">
<Locks>
<Lock resource_type="OBJECT" request_mode="X" request_status="GRANT" request_count="1" />
</Locks>
</Object>
<Object name="SalesOrderDetail" schema_name="Sales">
<Locks>
<Lock resource_type="OBJECT" request_mode="X" request_status="GRANT" request_count="1" />
</Locks>
</Object>
<Object name="SalesOrderHeader" schema_name="Sales">
<Locks>
<Lock resource_type="OBJECT" request_mode="X" request_status="GRANT" request_count="1" />
</Locks>
</Object>
I was expecting the table lock on SalesOrderDetail however, I don't understand why the table lock has been taken on the Person Table and the SalesOrderHeader table
I can confirm the locks are present by trying to SELECT *
from one of the tables which is then blocked.
Why are tables that are not being updated locked by the update statement?