Reputation: 408
I am using SQLserver 2008 R2 edition. I am trying to create a database using SQL CMD.
When I try to run the following command
Sqlcmd -S 10.2.202.213 -U sa -P 123@123 -Q "create database 125Build5"
I get the following error:
Msg 102, Level 15, State 1, Server WS-INBLR567, Line 1 Incorrect syntax near '125'.
If I use the database name that does not start with a number, something like 'Build5125', then it works. However I can create the database from SSMS without any problem.
Upvotes: 0
Views: 2486
Reputation: 29214
Try:
create database [125Build5]
The rules for identifiers state than they must begin with a letter among other things. You can get around that by enclosing them in brackets or double quotes.
Upvotes: 5
Reputation: 33914
I'd really encourage you to re-think creating a database that starts with a number, as it's going to make cross-database selects miserable by always requiring a qualifier.
However, that said, just wrap the name of the database in brackets, like [123Whatever]
. The brackets tell SQL to take the name as literal, so you can break whatever standard normal naming rules you want, including spaces or other special characters. The reason SSMS lets you start with a number is because the SQL statement it executes behind the scenes uses these brackets.
Upvotes: 2