Why is SQL Server '=' comparator case insensitive?
I just realized that SQL server '='
comparator when used for text comparison is case insensitive. I have a few questions regarding this functionality:
lower
function to ensure the text comparison is insensitive till now. Is it still a good idea to follow the same? '='
operator defaulting to case insensitive comparison? 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
SELECT *
FROM [Table_1] a inner join
[Table_2] b on a.Col1=b.Col2 collate Modern_Spanish_CS_AI
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?
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.
链接地址: http://www.djcxy.com/p/75186.html