sql-server – SQL Server中的区分大小写的变量

前端之家收集整理的这篇文章主要介绍了sql-server – SQL Server中的区分大小写的变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带有几个数据库sql Server.我希望其中一个数据库对变量名称区分大小写,而其他数据库则不区分大小写.

我需要更改设置,以便我可以毫无错误地运行此脚本

DECLARE @A int
DECLARE @a int

如何将一个数据库更改为区分大小写(对于其变量名称),同时允许实例上的其他数据库对变量名称不区分大小写?

解决方法

您需要将服务器排序规则更改为区分大小写以获取所需的行为.仅更改数据库的排序规则是不够的.

sql Server安装的默认排序规则sql_Latin1_General_CP1_CI_AS不区分大小写.

听起来您想要将服务器的排序规则修改为不区分大小写的排序规则.选择一个_CS. _CI表示“不区分大小写”,区分大小写是_CS.也许你会想要Latin1_General_CS_AS.

这是对Changing SQL Server collation to case insensitive from case sensitive?上一个问题的一个很好的答案.

SQL Server Books Online开始:

07002

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

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

    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.

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

SELECT SERVERPROPERTY('collation');

sql_Latin1_General_CP1_CI_AS
(1 row(s) affected)

猜你在找的MsSQL相关文章