Sqlserver deadlock com microsoft. sqlserver. jdbc. SQLServerException: Transaction (Process ID 52) was deadlock

Java multithreading operates the SQLSERVER database and executes the update operation; report errors:

First, check the specific deadlock program of the database and kill the deadlock process using data temporarily.

--查询数据库的死锁连接
SELECT REQUEST_SESSION_ID,OBJECT_NAME(RESOURCE_ASSCOIATED_ENTITY_ID) FROM SYS.DM_TRAN_LOCKS WHERE RESOURCE_TYPE='OBJECT'

--查出死锁的进程ID,使用如下脚本杀掉死锁进程
Declare @SPID INT
    SET @SPID=进程ID
Declare @sql VARCHAR(1000)
    SET @sql='KILL '+CAST(@SPID AS VARCHAR)
    EXEC(@sql)

However, after the above processing, the program will still deadlock. Later, it was found that there was a problem with the database table settings.

--如下的更新语句,多线程执行 造成TABLE死锁
UPDATE TABLE SET NAME='TEST' WHERE ID='12345'
解决方法:
    在数据库中将TABLE表的ID字段设置为主键 Primary Key,然后问题得到解决。
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>