久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 MOVE 確定 DB RESTORE 的 SQL 數據路徑

Determining SQL data path for DB RESTORE with MOVE(使用 MOVE 確定 DB RESTORE 的 SQL 數據路徑)
本文介紹了使用 MOVE 確定 DB RESTORE 的 SQL 數據路徑的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試編寫一個自動恢復數據庫備份的腳本.我知道我可以使用以下 RESTORE 命令:

I'm trying to write a script which automatically restores a database backup. I know I can use the following RESTORE command:

RESTORE DATABASE [DBRestoredName] 
FROM  DISK = N'C:\path\to\backup.bak' 
WITH  FILE = 1,  
MOVE N'DBNAME' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\DBNAME.mdf',  
MOVE N'DBNAME_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\DBNAME.ldf',  
NOUNLOAD

這樣做的問題是我希望能夠在運行時確定 SQL 服務器的數據位置(即 TO 路徑),以便恢復的數據庫與該服務器上的其他數據庫保持一致.

The problem with this is I want to be able to determine the SQL server's data location (i.e. the TO path) at run-time so the restored database is placed consistently alongside other databases on this server.

要恢復的數據庫在要恢復到的服務器上不存在,我需要 MOVE 語句,因為源服務器可能是 SQL Server 2005,目標是 2008,因此備份文件中包含的文件路徑是不可取.

The database being restored won't exist on the server it's being restored to and I require the MOVE statements as the source server is likely to be SQL server 2005 and the target is 2008 therefore the file paths included in the backup file are not desirable.

那么我可以通過哪些方式以編程方式確定 SQL 數據位置?

So what ways could I determine the SQL data location programmatically?

推薦答案

我發現的唯一可行的解??決方案是從您的 T-SQL 代碼中檢查注冊表:

The only viable solution I found is inspecting the registry from your T-SQL code:

DECLARE @filepath NVARCHAR(260)

EXEC master.dbo.xp_instance_regread 
        N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', 
        N'DefaultData', 
        @filepath output, 'no_output' 

SELECT @filepath as 'Your default data directory'

我可以發誓數據路徑將存儲在 SERVERPROPERTY 或動態管理視圖 (DMV) 中的某處 - 但沒有運氣......

I could have sworn that data path would be stored somewhere in a SERVERPROPERTY or a Dynamic Management View (DMV) - but no luck ......

更新:正如@Mike 指出的 - 在 SQL Server 2012 和更新版本中,該信息可作為 SERVERPROPERTY 使用:

Update: as @Mike pointed out - in SQL Server 2012 and newer, that information is available as a SERVERPROPERTY:

SELECT 
    DefaultDataPath = SERVERPROPERTY('InstanceDefaultDataPath'),
    DefaultLogPath = SERVERPROPERTY('InstanceDefaultLogPath')

這篇關于使用 MOVE 確定 DB RESTORE 的 SQL 數據路徑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 久久三区 | 日韩av福利在线观看 | 日韩欧美日韩在线 | jizz在线免费观看 | 久久精品免费观看 | 超碰91在线| 亚洲444kkkk在线观看最新 | 黄免费看| 国产精品一区免费 | 欧美精品在线一区二区三区 | av黄色片在线观看 | 日韩欧美一区二区在线播放 | 91天堂网 | 一级大片免费 | 精品国产乱码一区二区三区a | 97精品一区二区 | 免费观看一级黄色录像 | 国产成人精品一区二区三区在线观看 | 日韩精品在线一区 | 成人久久一区 | 六月成人网 | 精品国产欧美日韩不卡在线观看 | 91精品中文字幕一区二区三区 | 黄色香蕉视频在线观看 | 99精品在线| 在线资源视频 | 久草福利| 一级免费a | 久久99精品久久久久 | 久久青青 | 国产不卡一区在线观看 | 国产精品爱久久久久久久 | 羞视频在线观看 | 日韩欧美国产精品一区 | 激情福利视频 | 粉嫩粉嫩芽的虎白女18在线视频 | 一级黄色日本片 | 久久草视频 | 国产成人自拍一区 | 国产精品夜夜夜一区二区三区尤 | 精品一区二区三区四区在线 |