gpt4 book ai didi

SQL Server - 参数名称中的无效字符

转载 作者:行者123 更新时间:2023-12-02 01:21:31 25 4
gpt4 key购买 nike

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

给定一些简单的东西,比如 SELECT * FROM tblTest WHERE testid = @[X] ,例如,如果 X 包含连字符,则该语句将失败。参数名称的有效字符是什么?

最佳答案

在在线 SQL 书籍中搜索“标识符”,您应该会找到:

常规标识符的规则

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:

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

Subsequent characters can include the following:

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

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 书籍中搜索“分隔标识符”,您应该会找到:

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 - 参数名称中的无效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/751719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com