question

cstephen avatar image
cstephen asked

how to restore database .bak file with query including .mdf and .ldf in same path

i want to restore my database .bak file in my machine.i am having sqlserver 2005 in my machine.through query i want to restore and .mdf and .ldf file in same location.
backuprestore
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
Use the [`RESTORE`][1] command. The shortest form is: RESTORE DATABASE < > FROM DISK = '< >' There are lots of examples in the [MSDN documentation for the `RESTORE` command][1]. You might need to read examples D (Restoring a database and move files) and E (Copying a database using BACKUP and RESTORE) in particular. [1]: http://msdn.microsoft.com/en-us/library/ms186858(v=sql.90).aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

DharmanDave avatar image
DharmanDave answered
The following syntax should help: RESTORE DATABASE [DB_NAME] FROM DISK = N'BACKUP_FILE_PATH/BACKUP_FILE_NAME.bak' WITH FILE = 1, MOVE N'MDF_FILE_NAME' TO N'FILE_PATH/MDF_FILE_NAME.mdf', MOVE N'LOG_FILE_NAME' TO N'FILE_PATH/LOG_FILE_NAME.ldf', NOUNLOAD, STATS = 10 GO For your convenience, you can use the wizard --> Name the DB you want to restore--> Select the .bak file 'From Device'--> Select the Backup file name using checkbox--> Go to Options --> Set the same path for both .mdf and .ldf files--> Click on the Script button at the top of the window and generate the restore script specific to your path. Hope this helps !!
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TimothyAWiseman avatar image TimothyAWiseman commented ·
I put your code sample into a code block, I think it looks a bit closer to what you probably intended.
1 Like 1 ·
ramesh 1 avatar image
ramesh 1 answered
RESTORE DATABASE [TEST] FILE = N'TEST' FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER05\MSSQL\Backup\Profiler.bak' WITH FILE = 1, NOUNLOAD, **REPLACE**, STATS = 10 GO YOU CAN EVEN CHOOSE REPLACE THEN DATABASE WILL BE REPLACED WITH NEW ONE
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.