加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 06:30:37 所属栏目:MsSql教程 来源:网络整理
导读:我有一个带有几个数据库的SQL Server.我希望其中一个数据库对变量名称区分大小写,而其他数据库则不区分大小写. 我需要更改设置,以便我可以毫无错误地运行此脚本 DECLARE @A intDECLARE @a int 如何将一个数据库更改为区分大小写(对于其变量名称),同时允许实例
我有一个带有几个数据库的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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读