query for backup a database at another location in file system

穿精又带淫゛_ 提交于 2019-12-10 02:36:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!