Creating database fails

M

Michael Jackson

I'm trying to create a SQL Server 2000 database via the following TSQL code
in .NET 2003.
if not exists (SELECT * FROM dbo.sysdatabases WHERE name='Test-Co') create
database Test-Co
I get an error message regarding the dash in the database name. I know SQL
Server allows database names with dashes in them.

Any ideas.

Michael
 
M

Michael Jackson

Never mind. I had a mental lapse.

Placing square brackets around the database name solved the problem.

Michael
 
W

William \(Bill\) Vaughn

Just don't. Do yourself (and everyone that has to access the database) and
remove the minus sign. Leave out the spaces too.
Sure, bracketing the name will help, but every single application you or
anyone writes will have to do the same. Keep your names simple so the tools
and code can be written more easily.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
M

Mark Rae

Placing square brackets around the database name solved the problem.

As a general rule, if you ever have to put square brackets round a SQL
Server object, you should seriously consider renaming that object to
something more sensible...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top