SQL Server-参数名称中的无效字符 [英] SQL Server - Invalid characters in parameter names

查看:163
本文介绍了SQL Server-参数名称中的无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道在SQL参数名称中使用的有效字符是什么.

I need to know what are the valid characters to use in a SQL parameter name.

给出类似于SELECT * FROM tblTest WHERE testid = @[X]的简单内容,例如,如果X包含连字符,则该语句将失败.参数名称的有效字符是什么?

Given something simple like SELECT * FROM tblTest WHERE testid = @[X], if X contains a hyphen, for instance, the statement will fail. What are the valid characters for parameter names?

推荐答案

在您的SQL联机丛书中搜索标识符",您应该找到:

Search for "Identifiers" in your SQL Books online, and you should find:

常规标识符规则

常规标识符格式的规则取决于数据库 兼容性级别.可以使用sp_dbcmptlevel设置此级别. 当兼容性级别为90时,将应用以下规则:

The rules for the format of regular identifiers depend on the database compatibility level. This level can be set by using sp_dbcmptlevel. When the compatibility level is 90, the following rules apply:

第一个字符必须是以下字符之一:

The first character must be one of the following:

  • Unicode标准3.2定义的字母.字母的Unicode定义包括从a到z的拉丁字符,
    从A到Z,以及其他语言的字母字符.
  • 下划线(_),符号(@)或数字符号(#).
  • 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 (#).

标识符开头的某些符号具有特殊含义 在SQL Server中的含义.以at开头的常规标识符 符号始终表示局部变量或参数,不能使用 作为任何其他类型对象的名称.开始的标识符 带有数字符号的符号表示临时表或过程.一个 以双数字符号(##)开头的标识符表示全局 临时对象.虽然数字符号或双数字符号 字符可用于开头其他类型的对象的名称, 我们不建议您这样做.

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.

某些Transact-SQL函数的名称以符号后缀double开头 (@@).为避免与这些功能混淆,请勿使用 以@@开头的名称.

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 @@.

后续字符可以包括以下内容:

Subsequent characters can include the following:

  • Unicode标准3.2中定义的字母.
  • 基本拉丁文或其他国家文字的十进制数字.
  • at符号,美元符号($),数字符号或下划线.
  • Letters as defined in the Unicode Standard 3.2.
  • Decimal numbers from either Basic Latin or other national scripts.
  • The at sign, dollar sign ($), number sign, or underscore.

标识符不得为Transact-SQL保留字. SQL服务器 保留保留字的大写和小写版本. 不允许使用空格或特殊字符.补充 不允许使用字符.

The identifier must not be a Transact-SQL reserved word. SQL Server reserves both the uppercase and lowercase versions of reserved words. Embedded spaces or special characters are not allowed. Supplementary characters are not allowed.

在您的SQL联机丛书中搜索分隔标识符",您应该找到:

Search for "delimited identifiers" in your SQL Books online, and you should find:

标识符的主体可以包含 字符中的任意组合 当前代码页,但 分隔字符本身.为了 例如,分隔标识符可以 包含空格,任何有效字符 常规标识符,以及任何一个 以下字符.

The body of the identifier can contain any combination of characters in the current code page, except the delimiting characters themselves. For example, delimited identifiers can contain spaces, any characters valid for regular identifiers, and any one of the following characters.

tilde (~)                hyphen (-)   
exclamation point (!)    left brace ({)   
percent (%)              right brace (})   
caret (^)                apostrophe (')   
ampersand (&)            period (.)   
left parenthesis (()     backslash (\)   
right parenthesis ())    accent grave (`)

马克

这篇关于SQL Server-参数名称中的无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆