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

标签 sql-server sql-server-2008

我有一个包含多个数据库的 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 :

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.

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

关于sql-server - SQL Server 中区分大小写的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6559254/

相关文章:

c# - 使用 SqlCommandBuilder 时出现异常 "Incorrect syntax near ' System'"

php - mysql php pdo选择行值日期记录的一部分

sql - 如何更新具有外键的2个表中的2列

sql - 在不忽略空值的情况下计算 SQL Server 中的平均值

c# - 每个月有两个日期的日子

sql-server - 取消过期的 SQL Server 登录密码(密码无法更改)

php - 给出警告 : sqlsrv_query() expects parameter 1 to be resource, 字符串

sql - 连续日期的分组岛,包括错过的周末

asp.net - 事后在 ASP.NET Web 应用程序中实现安全性

sql-server-2008 - SQL Server 网络服务帐户权限