为什么 SQL Server 是“=”?比较器不区分大小写?
我刚刚意识到 SQL Server '='
比较器在用于文本比较时不区分大小写。关于此功能,我有几个问题:
- 这对于所有数据库都相同还是特定于 SQL Server?
- 到目前为止,我一直在使用
lower
函数来确保文本比较不敏感。遵循同样的做法仍然是一个好主意吗? - 我们如何在 SQL Server 中进行区分大小写的比较?
- 为什么
'='
运算符默认不区分大小写比较?
I just realized that SQL server '='
comparator when used for text comparison is case insensitive. I have a few questions regarding this functionality:
- Is this the same for all databases or specific to SQL server?
- I have been using the
lower
function to ensure the text comparison is insensitive till now. Is it still a good idea to follow the same? - How can we do case sensitive comparisons in SQL server?
- Why is
'='
operator defaulting to case insensitive comparison?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,区分大小写与等号无关。
区分大小写由数据库的排序规则决定 - 请参阅有关详细信息,请参阅文档。
No, case sensitivity has nothing to do with the equals sign.
Case sensitivity is determined by the collation for the database -- see the documentation for details.
区分大小写仅取决于排序规则。
您可以在每个
'='
操作中指定排序规则Case sensitivity depends only on the collation.
You can specify the collation within each
'='
operation绝对不是。如果这样做,您通常会阻止使用索引。普通旧=(或<或>或其他)是否有效取决于您选择的整理。不要“只是为了安全”而这样做。测试将确保您做对了。
Absolutely not. You will generally preclude the use of an index if you do this. Plain old = (or < or > or whatever) will either work or not depending on the collating you have chosen. Do not do this "just to be safe". Testing will make sure you've got it right.
SQL Server 中的操作是否区分大小写是在安装期间设置数据库排序规则时确定的。此时,您可以选择将 SQL Server 安装为不区分大小写(默认)或区分大小写。
http://msdn.microsoft.com/en-我们/库/aa197951(v=sql.80).aspx
The case sensitivity of operations in SQL Server is determined during installation when you set the collation for the database. At that point in time you can choose to install SQL Server as case insensitive (default) or case sensitive.
http://msdn.microsoft.com/en-us/library/aa197951(v=sql.80).aspx
比较的完成方式取决于您为该字段选择的排序规则。如果您将字段更改为使用区分大小写的排序规则,则比较将区分大小写。
默认情况下,字段使用数据库的排序规则集,但每个字段都可以有自己的排序规则设置。
How the comparison is done depends on the collation that you have chosen for the field. If you change the field to use a case sensetive collation, the comparisons will be case sensetive.
By default fields use the collation set for the database, but each field can have it's own collation setting.