Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query for backup a database at another location in file system

BACKUP DATABASE <myDataBaseName> TO DISK = 'C:\PathtoBackup\FileName.bak'

this query is worked for a database which is created in the gui of SQLServer express edition

I have attached my database which is physically at D drive(D:\testing.mdf) to SQLServer using GUI in SQlServer Mgmt Studio.After attaching, SSMS displays the database name as "D:\testing.mdf" in Object explorer rather than testing. SELECT DB_NAME() AS DatabaseName.

This query results the same that "D:\testing.mdf"

The above mentioned BACKUP query is not worked for later

 BACKUP DATABASE testing TO DISK = 'C:\PathtoBackup\testing.bak'

the following error has been shown

Msg 911, Level 16, State 11, Line 1
Could not locate entry in sysdatabases for database 'testing'. No entry found with that name. Make sure that the name is entered correctly.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally

I have tried like this

BACKUP DATABASE D:\testing.mdf TO DISK = 'C:\PathtoBackup\testing.bak'

the following error has been shown

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'D'.

What should I do to backup that file which is at different location in filesystem

like image 739
Siva Sankaran Avatar asked Sep 18 '10 13:09

Siva Sankaran


2 Answers

Thank you @u07ch

I got it.Finally I got the desired result by your tip.

BACKUP DATABASE [D:\testing.mdf] TO disk = 'C:\PathToBackup\BackupFileName.bak'

The backup file has created successfully.

like image 133
Siva Sankaran Avatar answered Oct 14 '22 04:10

Siva Sankaran


Path can be any location on your system so following query is working fine to take backup of a database: backup database empdb to disk = 'c:/empdb.bak'

like image 36
pooja Avatar answered Oct 14 '22 05:10

pooja