Restore SQL Server database backup to other directory than root I have a database backup file (db.bak) which I want to restore and import in my SQL Server 2008 R2 instance. However, the database takes approx 1 GB of space, and my C: partition is really strained at the moment - I don't have that much space left. (Yes, I know this is bad, but there's nothing I can do about it at the moment...)

I do have some space on my D:\ partition - can I somehow restore the backup and use a location on D:\ instead? If so, how?
restore database YourDatabase
from disk = 'C:\db.bak'
with 
    move 'YourDataFile' to 'D:\YourNewDir\YourNewDataFileName.mdf',
    move 'YourLogFile' to 'D:\YourNewDir\YourNewLogFileName.ldf'


The above command will restore your database but move your database files to a different location as per your specifications.  To get a list of database files contained in the backup (I just used the logical names of YourDataFile and YourLogFile), you can run the following command:

restore filelistonly
from disk = 'C:\db.bak'


If you want do to this through the GUI, then in the Restore Database dialog you can click on the item Files on the left, and you will see your database files listed.  There are elipses buttons next to those file names, and you can click that to change the path.  Likewise, you can just double click on the text box that has the file names themselves and change that to reflect the new path.  Below is a screenshot of what I explained: