且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server 存储过程区分大小写?

更新时间:2022-12-18 08:01:39

你说得对.数据库整理不控制变量名称区分大小写 - 服务器 整理可以.

You are right. Database collation does not control variables name case sensitivity - server collation does.

任何其他对象名称(例如表、视图、列)都遵循数据库整理规则.在您的情况下,这意味着不区分大小写,因为您的数据库是CI(不区分大小写).

Any other object name (e.g. table, view, column) follows database collation rules. In your situation, that means case insensitive, since your database is CI (case insensitive).

来自 SQL Server 联机丛书:

标识符的排序规则取决于定义它的级别.

COLLATE (Transact-SQL)

The collation of an identifier depends on the level at which it is defined.

  • 实例级对象的标识符,例如登录名和数据库名称,被分配了实例的默认排序规则.
  • 数据库中对象的标识符,例如表、视图和列名,被分配了数据库的默认排序规则.

  • Identifiers of instance-level objects, such as logins and database names, are assigned the default collation of the instance.
  • Identifiers of objects within a database, such as tables, views, and column names, are assigned the default collation of the database.

例如,两个名称仅大小写不同的表可以在区分大小写的数据库中创建,但不能在不区分大小写的数据库中创建.有关详细信息,请参阅数据库标识符.

For example, two tables with names different only in case may be created in a database with case-sensitive collation, but may not be created in a database with case-insensitive collation. For more information, see Database Identifiers.

变量GOTO标签临时存储过程临时表的标识符是在服务器实例的默认排序规则中.

The identifiers for variables, GOTO labels, temporary stored procedures, and temporary tables are in the default collation of the server instance.

当连接上下文与一个数据库相关联时,可以创建变量、GOTO 标签、临时存储过程和临时表,然后在上下文切换到另一个数据库时引用.

Variables, GOTO labels, temporary stored procedures, and temporary tables can be created when the connection context is associated with one database, and then referenced when the context has been switched to another database.

您可以使用以下方法检查您的服务器排序规则:

You can check your server collation using:

SELECT SERVERPROPERTY('collation');

SQL_Latin1_General_CP1_CI_AS
(1 row(s) affected)

另见