Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to handle the stored procedure of database lock in sql

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report