Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Databases starting with a number?

Author  Topic 

mb25stan2
Starting Member

3 Posts

Posted - 2010-08-30 : 17:30:59
The company I work for has a naming convention for the sql databases. The begin with a 2 digit number then name. I'm trying to write a simple vbscript to create and restore a database with the name 09company but it appears that sql doesn't like the fact that the database starts with a number. This is even more baffling as there is already a 01company database within the sql instance?
Any ideas?
Thanks
Mark

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-30 : 17:54:19
It's a problem with your vbscript as numbers are allowed as the prefix.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mb25stan2
Starting Member

3 Posts

Posted - 2010-08-30 : 18:07:58
Thanks for replying.
In response to your reply why then can the script create any database name other than when I prefix it with a number?
I've tried running a simple create command through sqlcmd and get the same problem, no number prefix no problem, number prefix can't create.
Mark
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-30 : 18:08:57
Post the command and error.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mb25stan2
Starting Member

3 Posts

Posted - 2010-08-30 : 18:36:59
serverName = "LOCALHOST\SQLEXPRESS"
set cn = createobject("ADODB.Connection")
The script is:


set cmd = createobject("ADODB.Command")
cn.open "Provider=SQLOLEDB.1;Data Source=" & serverName & ";Integrated Security=SSPI;Initial Catalog=Master"
cmd.activeconnection = cn
cmd.commandtext = "exec sp_helpdb"
databasename="02company"

cmd.commandtext = "CREATE DATABASE " & databasename
cmd.CommandTimeout = 60 * 20
cmd.execute
wscript.echo "create Complete"
cn.close

The error I get is:

"incorrect syntax near '02'.


I'm new to all this so your help is very much appreciated.
Thanks
Mark
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-30 : 19:00:00
Put square brackets around it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-30 : 23:03:27
quote:
Originally posted by tkizer

Put square brackets around it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


you knew that was the problem the second you read the 1st post
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-31 : 05:54:12
quote:
Originally posted by mb25stan2

serverName = "LOCALHOST\SQLEXPRESS"
set cn = createobject("ADODB.Connection")
The script is:


set cmd = createobject("ADODB.Command")
cn.open "Provider=SQLOLEDB.1;Data Source=" & serverName & ";Integrated Security=SSPI;Initial Catalog=Master"
cmd.activeconnection = cn
cmd.commandtext = "exec sp_helpdb"
databasename="02company"

cmd.commandtext = "CREATE DATABASE " & databasename
cmd.CommandTimeout = 60 * 20
cmd.execute
wscript.echo "create Complete"
cn.close

The error I get is:

"incorrect syntax near '02'.


I'm new to all this so your help is very much appreciated.
Thanks
Mark


It is better to use company02 or company_02. Dont name an object starting with a digit

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

naveengopinathasari
Yak Posting Veteran

60 Posts

Posted - 2010-08-31 : 06:26:27
Try giving with [02Company]

Lets unLearn
Go to Top of Page
   

- Advertisement -