Update from Sync Service
This commit is contained in:
33
OneNote/数据库知识库/工具脚本/运行中数据库收缩脚本.md
Executable file
33
OneNote/数据库知识库/工具脚本/运行中数据库收缩脚本.md
Executable file
@@ -0,0 +1,33 @@
|
||||
use master
|
||||
go
|
||||
|
||||
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
|
||||
drop procedure [dbo].[p_killspid]
|
||||
GO
|
||||
|
||||
create proc p_killspid
|
||||
@dbname varchar(200) --要关闭进程的数据库名
|
||||
as
|
||||
declare @sql nvarchar(500)
|
||||
declare @spid nvarchar(20)
|
||||
|
||||
declare #tb cursor for
|
||||
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
|
||||
open #tb
|
||||
fetch next from #tb into @spid
|
||||
while @@fetch_status=0
|
||||
begin
|
||||
exec('kill '+@spid)
|
||||
fetch next from #tb into @spid
|
||||
end
|
||||
close #tb
|
||||
deallocate #tb
|
||||
go
|
||||
|
||||
--用法
|
||||
exec p_killspid 'safeMonitorMgr'
|
||||
go
|
||||
DBCC SHRINKDATABASE (safeMonitorMgr)
|
||||
go
|
||||
|
||||
drop proc p_killspid
|
||||
Reference in New Issue
Block a user