SQL 單使用者 鎖表 解鎖,sql解鎖

來源:互聯網
上載者:User

SQL 單使用者 鎖表 解鎖,sql解鎖

USE master;
GO

DECLARE @SQL VARCHAR(MAX);

SET @SQL=''

SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID)

FROM sysprocesses

WHERE dbid=DB_ID('WMS.MDF');

EXEC(@SQL);

GO

ALTER DATABASE [WMS.MDF] SET MULTI_USER;

 

查看被鎖表:

select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName  
from   sys.dm_tran_locks where resource_type='OBJECT'

spid   鎖表進程
tableName   被鎖表名

解鎖:

declare @spid  int
Set @spid  = 57 --鎖表進程
declare @sql varchar(1000)
set @sql='kill '+cast(@spid  as varchar)
exec(@sql)

 

相關文章

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.