当我在数据库名称中包含数字字符时,SQL Server查询创建数据库给我一个错误

我在Microsoft SQL Server 2005中运行简单的SQL查询以创建数据库时遇到问题,我不知道为什么.

当我运行此查询时

CREATE DATABASE 4444-virtual2

我收到此错误

Incorrect syntax near ‘4444’.

如果我在名称中创建一个包含数值的数据库表,是否还有必须指定的内容?还是我忘记了什么?

最佳答案
数据库名称需要为start with a letter, underscore, at sign or number sign

The first character must be one of the
following:

  • A letter as defined by the Unicode
    Standard 3.2. The Unicode definition
    of letters includes Latin characters
    from a through z, from A through Z,
    and also letter characters from other
    languages.

  • The underscore (_), at sign (@), or
    number sign (#).

Certain symbols at the beginning of an
identifier have special meaning in SQL
Server. A regular identifier that
starts with the at sign always denotes
a local variable or parameter and
cannot be used as the name of any
other type of object. An identifier
that starts with a number sign denotes
a temporary table or procedure. An
identifier that starts with double
number signs (##) denotes a global
temporary object. Although the number
sign or double number sign characters
can be used to begin the names of
other types of objects, we do not
recommend this practice.

Some Transact-SQL functions have names
that start with double at signs (@@).
To avoid confusion with these
functions, you should not use names
that start with @@.

除非您想用双引号“4444-virtual2”或方括号[4444-virtual2]分隔名称的每次使用.

转载注明原文:当我在数据库名称中包含数字字符时,SQL Server查询创建数据库给我一个错误 - 代码日志