问题
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
回答1:
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.
回答2:
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'
来源:https://stackoverflow.com/questions/3741846/query-for-backup-a-database-at-another-location-in-file-system