SQL Server:列排序规则对T-SQL指令的影响 [英] SQL Server: impact of column collation on T-SQL instructions

查看:68
本文介绍了SQL Server:列排序规则对T-SQL指令的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天发现(*),根据服务器的不同,我的TSQL命令区分大小写,这意味着当一个表的列名为 tableId 时,以下内容指令可能不会成功:

 从myTable 


取决于列的排序规则。当 Latin1_blablabla 时, SQL_Latin1_blablabla 似乎不区分大小写。



所以我的第一个问题是为什么!



第二个问题是:更改所有相关排序规则的最快方法(sp?)是什么?数据库中的列?



编辑:使事情变得很清楚:

  SELECT tableId FROM myTable 

在所有服务器上工作,而

 从myTable 

SELECT TableId仅在具有 SQL_Latin_blablabla 排序规则。注意两个字符串之间的区别。我们这里不是在谈论数据整理,而是在讨论这种整理对我们编写代码的方式的影响!



(*)在这里我可以使用一些额外的特定词在此发现之后使我的心态符合条件,但所有这些人都是成年的……

解决方案

来自marc_s



sys.objects,sys.columns等将列名和对象名存储在数据库的整理中。因此,二进制排序规则意味着将对象名称视为二进制...


I discovered(*) today that, depending on the server, my TSQL commands were case-sensitive, meaning that, when one table's column is named tableId, the following instruction might not succeed:

SELECT TableId FROM myTable

Depending on the column's collation. SQL_Latin1_blablabla seems not to be case-sensitive, when Latin1_blablabla is.

So my first question is WHY!!!

And the second one is: what is the quickest trick (sp?) to change all collations for all concerned columns in the database?

EDIT: to make things very clear:

SELECT tableId FROM myTable

Work on all servers while

SELECT TableId FROM myTable

Works only on the server with the SQL_Latin_blablabla collation. Notice the difference between the 2 strings. We are not talking here about data collation, but about the impact of this collation on the way we write code!

(*) I could use here some additional and specific word to qualify my state of mind after this 'discovery', but all of them are adult-rated ...

解决方案

Following on from marc_s

sys.objects, sys.columns etc store the column names and object names in the collation of the database. So, a binary collation means object names treated as binary...

这篇关于SQL Server:列排序规则对T-SQL指令的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆