SQL View Deadlock

Source: Internet
Author: User

 UseMasterDeclare @spid int,        @bl int,                @intCounter    int,        @intRowcount    int,        @intCountProperties   int,        @intTransactionCountOnEntry  int Declare  @tmp_lock_who Table(IDint Identity(1,1), spidsmallint, BLsmallint)  IF @ @ERROR<>0     SELECT @ @ERROR  Insert  into @tmp_lock_who(SPID,BL)Select  0, blocked from(Select *  fromSys.sysprocesseswhereBlocked>0) Awhere  not exists        (Select *  from(Select *  fromSys.sysprocesseswhereBlocked>0) bwhereA.blocked=spid)Union SelectSpid,blocked fromSys.sysprocesseswhereBlocked>0 IF @ @ERROR<>0 SELECT @ @ERROR  Select  @intCountProperties = Count(*),@intCounter = 1  from @tmp_lock_who  IF @ @ERROR<>0 SELECT @ @ERROR   if @intCountProperties=0BEGIN  SelectN'No blocking and deadlock information now'  asmessageENDELSEbegin  while @intCounter <= @intCountProperties begin  Select  @spid =spid@bl =BL from @tmp_lock_who whereId= @intCounter   begin  if @spid =0       SelectN'spid that caused the database deadlock:'+ CAST(@bl  as VARCHAR(Ten))+N'SQL:'   Else      SelectN'SPID:'+ CAST(@spid  as VARCHAR(Ten))+N'by spid:'+ CAST(@bl  as VARCHAR(Ten))+N'blocking, SQL:'  DBCCInputBuffer (@bl)  End Set @intCounter = @intCounter + 1 EndEnd

Select   request_session_id   spid,object_name(resource_associated_entity_id) tableName   from    where resource_type='OBJECT'

SQL View Deadlock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.