gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:09:42 30 4
gpt4 key购买 nike

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

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