To create a new database and populate it from a backup I typically do:
CREATE DATABASE MyDatabase -- I create an empty database
-- I retrieve the filepath of mdf and ldf files
DECLARE @FileData varchar(1000)
DECLARE @FileLog varchar(1000)
set @FileData = (select filename from MyDatabase.dbo.sysfiles where fileid = 1)
set @FileLog = (select filename from MyDatabase.dbo.sysfiles where fileid = 2)
-- I Restore the database from backup by substituting the mdf and ldf files
RESTORE DATABASE MyDatabase
FROM DISK = 'c:\Test\Test.bak'
WITH REPLACE,
MOVE 'MyApp_Data' TO @FileData, -- I forced the name to be MyApp_Data for simplicity
MOVE 'MyApp_Log' TO @FileLog -- I forced the name to be MyApp_Log for simplicity
How to do the same for the filestream data too? May I force the folder creation for filestream data or should I create it manually?
May you also comment on my approach?