Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>RESTORE FILELISTONLY produces a result set that is documented in the <a href="http://msdn.microsoft.com/en-us/library/ms173778.aspx" rel="nofollow noreferrer">MSDN</a>. You then need to iterate this result set and build an appropriate RESTORE ... MOVE... How you capture and iterate the result set depends on your environment. In a C# application you would use a SqlDataReader. In pure T-SQL you would use <a href="http://www.sommarskog.se/share_data.html#INSERTEXEC" rel="nofollow noreferrer">INSERT ... EXEC</a>. </p> <p>The skeleton of a pure SQL solution would be:</p> <pre><code>declare @filelist table (LogicalName nvarchar(128), PhysicalName nvarchar(260), Type char(1), FilegroupName varchar(10), size int, MaxSize bigint, field int, createlsn bit, droplsn bit, uniqueid uniqueidentifier, readonlylsn bit, readwritelsn bit, backupsizeinbytes bigint, sourceblocksize int, filegroupid int, loggroupguid uniqueidentifier, differentialbaselsn bit, differentialbaseguid uniqueidentifier, isreadonly bit, ispresent bit, tdethumbprint varchar(5)); insert into @filelist exec sp_executesql N'restore filelistonly from disk=''D:\backups\my_backup.bak'''; set @sql = N'RESTORE database my_database from disk ''D:\backups\my_backup.bak'' with '; select @sql = @sql + N' move ' + LogicalName + N' to ' udf_localFilePath(PhysicalName) + N',' from @filelist; set @sql = substring(@sql, 1, len(@sql)-1); -- remove last ',' exec sp_executesql @sql; </code></pre> <p>This is not actual working code, but just to get you the idea. You can also use a cursor instead of the non-standard assignment-inside-query construction of @sql</p> <p>Be aware that the list of columns in the result set of <code>RESTORE FILELISTONLY</code> differs between SQL Server versions. Refer to the target version specifications for the correct list.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload