SQL Server – Equivalent of Relocate All Files to Folder Option

sql server

When restoring database using the GUI, there's an option "relocate all files to folder" which is very convenient.

I wonder if there's the same thing if I'm restoring db using T-sql?
To me, finding out logical file names then put into the move clause seems to be too tedious and unnecessary.

Best Answer

There is no shortcut, no. The backup contains the original path to each and every file - a restore will try to put each file in its original location, unless you override it explicitly, and you have to do that for each file using WITH MOVE.