Mill the stored procedure for other database processes

xiaoxiao2021-03-06  46

Enter Master, then kill all connections with the stored procedure to restore the database to restore the database; **** Kill all processes connected to a database: Create Proc Killspid (@dbname varchar (20)) as begin Declare @SQL NVARCHAR (500) declare @spid int set @ sql = 'declare getspid cursor for select spid from sysprocesses where dbid = db_id (' '' @ dbname '' ')' exec (@sql) open getspid fetch next from getspid into @spid while @@ Fetch_status <> -1 begin exec ('kill' @ spid) fetch next from getspid @spid endspid deallocate getSpid End

- Usage Use master exec killspid 'Database name "Carefully use, may result in data loss

转载请注明原文地址:https://www.9cbs.com/read-79921.html

New Post(0)