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 ‘[email protected]) fetch next from cur into @i end close cur deallocate cur --已关闭数据库连接 --还原数据库 RESTORE DATABASE @dbname FROM [email protected] WITH replace --还原数据库完毕
时间: 2024-11-03 03:26:46