Question

I have a table, say Administration, which have columns ObjectID, CustomerName, VisitDate,PlannedDateTime,TypeOfTransaction and i have a non unique clustered index on PlannedDateTime column.

For each PlannedDateTime value, we have many rows, say min of 20 duplicate values for each value of PlannedDateTime column. I am facing a deadlock issue when a procedure is trying to update VisitDate and TypeOfTransaction columns.

Though i am aware that uniquifier column is added by SQL Server to bring uniqueness to each duplicate value of PlannedDateTime , i want to understand how the locking works on the rows when there s an update on the table. Does it lock all the rows with the same value of PlannedDateTime or will lock only single row which is to be updated considering the uniquifier??

The data in the table is huge, say more than 10 million records.

Please share your thoughts...

Was it helpful?

Solution

SQL Server locking is dynamical. It will default to row-level locking, but could also escalate to table or partition level.

With an UPDATE, SQL Server uses mix of update and exclusive locks. Update locks are used while searching for the rows that shoud be updated, and once the row is found they are converted to exclusive locks. Exclusive locks are held until end of transaction.

To find out which lock are actually help by the session, start transaction, execute the update, and then check the sys.dm_tran_locks for the request_session_id in question.

To debug a deadlock, restart the service with trace flag 1222 set. Here's a good intro into solving deadlocks:

http://technet.microsoft.com/en-us/library/ms178104%28v=sql.105%29.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top