In fact, not only the situation described above will lock the table, there are many kinds of scenes that will put the table to lock the life and death, unlock is actually very simple, the following an example to explain:
1 Create a test table first:
Copy Code code as follows:
CREATE TABLE Test
(
TID INT IDENTITY (1,1)
)
2 Execute the following SQL statement to lock the table:
Copy Code code as follows:
SELECT * from Test with (Tablockx)
3 You can see which tables in the current library are deadlocked by using the following statement:
Copy Code code as follows:
SELECT request_session_id spid,object_name (resource_associated_entity_id) tablename
From sys.dm_tran_locks
WHERE resource_type= ' OBJECT '
4 The results of the above statement are as follows:
SPID: the lock process ID.
TableName: The name of the table in which the deadlock occurred.
5 You can unlock a table simply by using the KILL keyword to kill the locked process ID:
KILL 52