如何从备份文件中检索数据库的逻辑文件名
我正在研究如何使用 SQL 脚本 (T-SQL) 恢复数据库备份。步骤如下:
数据库
YourDB
具有完整备份YourBackUpFile.bak
。可以通过以下两个步骤恢复:第 1 步:从备份中检索数据库的逻辑文件名。
仅恢复文件列表 从磁盘 = 'D:BackUpYourBackUpFile.bak' 去
第 2 步:在后续步骤中使用
LogicalName
列中的值。----使数据库成为单用户模式 更改数据库 YourDB 设置单个用户为 立即回滚 ----恢复数据库 恢复数据库 YourDB 从磁盘 = 'D:BackUpYourBackUpFile.bak' 将“YourMDFLogicalName”移动到“D:DataYourMDFFile.mdf”, 将“YourLDFLogicalName”移动到“D:DataYourLDFFile.ldf”
我只是在如何获取 YourMDFLogicalName
和 YourLDFLogicalName
方面遇到问题。 有人可以帮我吗?
I was looking into the steps of how to Restore Database Backup using SQL Script (T-SQL). Here are the steps:
Database
YourDB
has full backupYourBackUpFile.bak
. It can be restored using following two steps:Step 1: Retrieve the logical file name of the database from the backup.
RESTORE FILELISTONLY FROM DISK = 'D:BackUpYourBackUpFile.bak' GO
Step 2: Use the values in the
LogicalName
column in the following step.----Make Database to single user Mode ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE ----Restore Database RESTORE DATABASE YourDB FROM DISK = 'D:BackUpYourBackUpFile.bak' WITH MOVE 'YourMDFLogicalName' TO 'D:DataYourMDFFile.mdf', MOVE 'YourLDFLogicalName' TO 'D:DataYourLDFFile.ldf'
I am just having problem on how to get the YourMDFLogicalName
and YourLDFLogicalName
.
Can any one help me with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
更新
根据Microsoft 网站:
UPDATE
According to Microsoft site:
逻辑文件名:是 Microsoft SQL Server 引用文件时使用的名称。该名称在数据库中必须是唯一的,并且符合标识符规则。该名称可以是字符或 Unicode 常量、常规标识符或分隔标识符。
来自:http://msdn.microsoft.com/en-us/ library/aa275464(v=sql.80).aspx
另外,从 Dalex 的脚本中,您可以只运行(无需所有表逻辑):
logical_file_name: is the name used in Microsoft SQL Server when referencing the file. The name must be unique within the database and conform to the rules for identifiers. The name can be a character or Unicode constant, a regular identifier, or a delimited identifier.
From: http://msdn.microsoft.com/en-us/library/aa275464(v=sql.80).aspx
Also, from Dalex's script, you can just run (without all the table logic):
脚本的更新版本:
Updated version of script:
如果您有原始数据库(从中获取备份文件),那么获取其逻辑名称的最简单方法是通过 :
或使用一个 T-SQL
这将与您在 RESTORE 命令中使用的逻辑名称相同。
If you have the original DB (from which the backup file was taken) then the easiest way to obtain its logical name is via :
or with one T-SQL
This would be the same logical_name you would use in the RESTORE command.
如果您手动进行更改,则可以使用以下查询找到相应的名称:
If you are making your changes manually, then you can find the corresponding names with the following query:
尝试以下代码:
Try following code: