标签:
declare @dbname varchar(20) --数据库名称 declare @filename varchar(200) --数据库备份文件 路径 set @dbname=‘MyTest‘ set @filename=‘D:\MyTest.bak‘ --关闭现有数据库连接 declare @i int declare cur cursor for select spid from sysprocesses where db_name(dbid)= @dbname open cur fetch next from cur into @i while @@fetch_status=0 begin exec(‘kill ‘+@i) fetch next from cur into @i end close cur deallocate cur --已关闭数据库连接 --还原数据库 RESTORE DATABASE @dbname FROM DISK=@filename WITH replace --还原数据库完毕
MSSqlServer 通过sql语句 还原数据库(已有备份文件)
标签:
原文地址:http://www.cnblogs.com/hetring/p/4441484.html