restore database 数据库名
from disk='x:\path\备份文件名'
with replace --强制替换已经存在的数据库,条件是要替换的数据库没有被使用.
为了断开对要替换的数据库的连接,你可以用下面的存储过程来关闭用户连接./*
关闭用户打开的进程处理
*/
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 '+rtrim(@spid))
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end --用法
use master
exec killspid '数据库名'
from disk='x:\path\备份文件名'
with replace --强制替换已经存在的数据库,条件是要替换的数据库没有被使用.
为了断开对要替换的数据库的连接,你可以用下面的存储过程来关闭用户连接./*
关闭用户打开的进程处理
*/
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 '+rtrim(@spid))
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end --用法
use master
exec killspid '数据库名'
解决方案 »
- C# 调用MFC ActiveX控件出错
- GridView 绑定数据源后(主从表)显示数据的问题?
- 有没有删除回收站内某个文件的函数?(注意:不是删除到回收站,也不是清空)
- C#运行中的出错
- On Error Resume Next
- webBrowser1 与 MessageBox的问题。。。。无语
- 谁能告诉我一个用ADO.net连接数据库的方法
- 在调用了BindingManagerBase.EndCurrentEdit()方法后,使用用DbDataAdapter.Update()方法提交数据库,为什么当前的DataGridCell的数据
- 最菜的问题:C#中怎样使用Len(),Str()这类最常用的函数
- 如何使用C#写的程序编译成能在没装Framework的Windows平台下运行。
- 请问如何编程读取系统信息
- 请问那为仁兄做过“系统信息的模块“??很急!!解决马上结账!
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 '+rtrim(@spid))
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end --用法
use master
exec killspid '数据库名'
这种方法是不是有点限制啊
如果给予的用户权限不允许操作master数据库怎么办?