Get the App
SLTechnology News&Howtos  ›  Database  › 

How to handle the stored procedure of database lock in sql

Shulou Source: shulou.com Published: 2022-05-31 19:26:04 11月17日 Update

This article introduces how to deal with the stored procedure of database lock in sql, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Zou Jian 2004.4 copied the code as follows: / *-- call the example exec p_lockinfo1-- * / alter proc p_lockinfo1 @ kill_lock_spid bit=1,-- whether to kill the deadlocked process, 1 kill, 0 only show @ show_spid_if_nolock bit=1-- if there is no deadlocked process, whether the normal process information is displayed, 1 shows, 0 does not display as declare @ count int,@s nvarchar (max), @ i int select id=identity (int,1,1) Flag, process ID=spid, thread ID=kpid, block process ID=blocked, database ID=dbid, database name = db_name (dbid), user ID=uid, user name = loginame, cumulative CPU time = cpu, login time = login_time, open transactions = open_tran, process status = status, workstation name = hostname, application name = program_name, workstation process ID=hostprocess, domain name = nt_domain, network card address = net_address into # t from (select flag = 'deadlocked process', spid Kpid,a.blocked,dbid,uid,loginame,cpu,login_time,open_tran, status,hostname,program_name,hostprocess,nt_domain,net_address, s1praga.spidjue s2prag0 from master..sysprocesses a join (select blocked from master..sysprocesses group by blocked) b on a.spid=b.blocked where a.blocked=0 union all select'| _ victim _ >', spid,kpid,blocked,dbid,uid,loginame,cpu,login_time,open_tran, status,hostname,program_name,hostprocess,nt_domain,net_address, s1=blocked S1 from master..sysprocesses a where blocked0) an order by S1 select @ count=@@rowcount,@i=1 if @ count=0 and @ show_spid_if_nolock=1 begin insert # t select flag = 'normal process', spid,kpid,blocked,dbid,db_name (dbid), uid,loginame,cpu,login_time, open_tran,status,hostname,program_name,hostprocess,nt_domain,net_address from master..sysprocesses set @ count=@@rowcount end if @ count > 0 begin create table # T1 (id int identity (1Power1) A nvarchar (max), b Int,EventInfo nvarchar (max) if @ kill_lock_spid=1 begin declare @ spid varchar (max), @ flag varchar (max) while @ I

Tags: Processes flags data databases deadlocks procedures processing storage code content time more users work help good transactions information interests addresses Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Linux Shulou Information Shulou Tech Info