Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  1. Is this the same for all databases or specific to SQL server?
  2. 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?
  3. How can we do case sensitive comparisons in SQL server?
  4. Why is '=' operator defaulting to case insensitive comparison?
like image 535
rkg Avatar asked Feb 08 '11 21:02

rkg


People also ask

Is SQL comparison case-sensitive?

In summary, comparisons are case sensitive if they involve a binary literal string or string expression, or a CHAR BINARY , VARCHAR BINARY , or BLOB column. Comparisons are not case sensitive if they involve only non-binary literal strings or string expressions, or CHAR , VARCHAR , ENUM , SET , or TEXT columns.

Why SQL Server is not case-sensitive?

SQL Server is, by default, case insensitive; however, it is possible to create a case-sensitive SQL Server database and even to make specific table columns case sensitive. The way to determine if a database or database object is to check its "COLLATION" property and look for "CI" or "CS" in the result.

Is Equal operator in SQL case-sensitive?

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.

Does SQL care about case sensitivity?

The SQL keywords (SELECT, FROM, WHERE, etc.) are case-insensitive, yet they are frequently expressed in all capitals. Table and column names are case-sensitive in some settings.


2 Answers

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.

like image 139
OMG Ponies Avatar answered Oct 15 '22 09:10

OMG Ponies


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
like image 21
pcofre Avatar answered Oct 15 '22 09:10

pcofre