Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL-Server: Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names

I made a script to restore .bak or backup files. It works for some databases, but not for one. How do I make it work for any type of .bak file ? This is in sql server 2008. The error message is -

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. 

Script -

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 
like image 993
Steam Avatar asked Mar 07 '14 09:03

Steam


People also ask

Is there a logical file in SQL Server?

SQL-Server: Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names - Stack Overflow SQL-Server: Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names

How to fix logical file is not part of database error?

Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names I made a script to restore .bak or backup files.

How to list logical file names in restore database?

Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally. Show activity on this post. And then replace logical name shown by RESTORE FILELISTONLY in script below

How to list the logical file names in MSG 3013?

Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally. The issue was that I was not referencing the logical files properly.


1 Answers

Please run below sql and check logical names

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

And then replace logical name shown by RESTORE FILELISTONLY in script below

--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 
like image 185
Saurabh Sinha Avatar answered Sep 21 '22 17:09

Saurabh Sinha