gpt4 book ai didi

SQL-Server:错误 - 逻辑文件不是数据库的一部分。使用 RESTORE FILELISTONLY 列出逻辑文件名

转载 作者:行者123 更新时间:2023-12-01 19:40:48 26 4
gpt4 key购买 nike

我制作了一个脚本来恢复 .bak 或备份文件。它适用于某些数据库,但不适用于某一数据库。如何使其适用于任何类型的 .bak 文件?这是在 sql server 2008 中。错误消息是 -

Msg 3234, Level 16, State 1, Line 1
Logical file 'Northwind_Data' is not part of database 'Northwind'.
Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

脚本 -

IF DB_ID('Northwind') IS NULL
BEGIN
RESTORE DATABASE [Northwind]
FILE = N'Northwind_Data'
FROM
DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak'
WITH FILE = 1,
MOVE N'Northwind_Data'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind.mdf',
MOVE N'Northwind_Log'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind_0.LDF',
NOUNLOAD, STATS = 10
END

最佳答案

请运行下面的sql并检查逻辑名称

RESTORE FILELISTONLY 
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak'

然后替换下面脚本中的RESTORE FILELISTONLY显示的逻辑名称

--If database already exists do not restore
IF DB_ID('Northwind') IS NULL
BEGIN
RESTORE DATABASE [Northwind]
FILE = N'Northwind_Data'
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak'
WITH
FILE = 1, NOUNLOAD, STATS = 10,
MOVE N'YOUR logical name of data file as shown by RESTORE FILELISTONLY command'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind.mdf',
MOVE N'YOUR logical name of Log file as shown by RESTORE FILELISTONLY command'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind_0.LDF'
END

关于SQL-Server:错误 - 逻辑文件不是数据库的一部分。使用 RESTORE FILELISTONLY 列出逻辑文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22245808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com