当单用户模式又不知道哪里占用数据库时~

USE master;
GO
DECLARE @SQL VARCHAR(3000);
SET @SQL = '';
SELECT @SQL = @SQL+'; KILL ' + RTRIM(SPID)
FROM [sys].[sysprocesses] AS sps
WHERE [sps].[dbid] = DB_ID('db_name');
SET @SQL = SUBSTRING(@SQL, 2, LEN(@SQL));
EXEC(@SQL);
GO

 

 

或查看用户及系统级别进程

 

*****查看用户级进程:

  select start_time,command,percent_complete,text,

  session_id,blocking_session_id

  from sys.dm_exec_requests r

  cross apply sys.dm_exec_sql_text(r.sql_handle) s

*****查看数据库状态:select * from SYS.DATABASES

 

posted @ 2018-05-15 14:24  郭大侠1  阅读(188)  评论(0编辑  收藏  举报