日期:2014-05-17 浏览次数:20454 次
create table #t
(id int not null identity(1,1), filenames varchar(500))
insert into #t(filenames)
exec master..xp_cmdshell 'dir /b/s e:\db_bk\*.bak'
declare @filename varchar(500),@tsql varchar(6000)
select @filename=max(replace(replace(filenames,'e:\db_bk\',''),'.bak',''))+'.bak'
from #t
where filenames is not null
select @tsql='restore database [数据库名] from disk=''e:\db_bk\'+@filename+''' with replace '
exec(@tsql)
drop table #t
USE msdb
GO
SELECT physical_device_name
FROM backupmediafamily
WHERE media_set_id = (
SELECT MAX(media_set_id)
FROM backupset
WHERE database_name = 'data'
AND backupset.[type] = 'D'
)