將資料庫 Restore 到 Master 資料庫所在的檔案路徑

IF db_id(‘db’) is null
BEGIN
 declare @filename nvarchar(1000)
 select @filename=filename from master.dbo.sysfiles where name=’master’
 set @filename=substring(@filename,1,charindex(‘master.mdf’,@filename,1)-1)
 declare @sql nvarchar(2000)
 set @sql=’restore database db from disk="C:dbDataSVRdb.bak" with move “db" to “‘
 set @sql=@sql + @filename + ‘db.mdf", move “db_log" to “‘
 set @sql=@sql + @filename + ‘db_log.ldf"‘
 exec(@sql)
END
ELSE
 PRINT ‘db 資料庫已經存在’

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: