Creating database fails

  • Thread starter Thread starter Michael Jackson
  • Start date Start date
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
 
Never mind. I had a mental lapse.

Placing square brackets around the database name solved the problem.

Michael
 
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.
__________________________________
 
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...
 
Back
Top