Strange sql backup behavior

Jan 26, 2007 2 Replies

I am trying to automate my backups using osql and the Windows task scheduler. I have run into a strange problem - my database name starts with a number (it is "4DHQ"). The SQL BACKUP command does not work with this database.



I racked my brain using osql and then decided to try it in HQ Administrator. I executed the following SQL"



BACKUP DATABASE 4DHQ TO DISK = 'C:\Documents and Settings\All Users\Documents\RMS BACKUP - HQ.BCK'"



The results were: An error occurred while executing query: Line 1: Incorrect syntax near '4'.


I tried the same string using a different test database (named "TEST") and it worked. Unfortunately, it's not so easy to change my database name now. It this a known bug in SQL?



Jason


Jason

Try putting [ ] around the offending name, i.e. [4DHQ]. SQL server usually does not like tables with spaces and other such issues- likely the same problem. By using the [] you can get it to behave a bit better.

Jerry

Amazing. Worked like a charm. Thank you so much.

Try putting [ ] around the offending name, i.e. [4DHQ]. SQL server usually does not like tables with spaces and other such issues- likely the same problem. By using the [] you can get it to behave a bit better.

Jerry

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required