/*断开所有用户打开的连接*/use master--一定要有这个goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[p_killspid]GOcreate proc p_killspid--创建存储过程@dbname sysname --要关闭进程的数据库名as declare @s nvarchar(1000)declare tb cursor local forselect s='kill '+cast(spid as varchar)from master..sysprocesses where dbid=db_id(@dbname)open tb fetch next from tb into @swhile @@fetch_status=0beginexec(@s)fetch next from tb into @sendclose tbdeallocate tbgo--用法 exec p_killspid 'lq4'--调用存储过程 这里的hj为数据库名--恢复数据库.RESTORE DATABASE hj FROM disk='d:\LQ_db_1200.BAK' --备份数据的位置--完成后,删除存储过程drop proc p_killspid
1500字范文,内容丰富有趣,写作好帮手!