Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would you want a case sensitive database?

What are some reasons for choosing a case sensitive collation over a case insensitive one? I can see perhaps a modest performance gain for the DB engine in doing string comparisons. Is that it? If your data is set to all lower or uppercase then case sensitive could be reasonable but it's a disaster if you store mixed case data and then try to query it. You have to then say apply a lower() function on the column so that it'll match the corresponding lower case string literal. This prevents index usage in every dbms that I've used. So wondering why anyone would use such an option.

like image 579
Khorkrak Avatar asked Jun 07 '10 00:06

Khorkrak


People also ask

Should a database be case-sensitive?

While for the most part I agree with you that computers (programming languages, databases, file systems, URLs, passwords, etc) should be case-sensitive, all systems are implemented independently and may or may not adhere to standards that may or may not exist.

Why is case sensitivity important?

Case sensitive means that it matters if characters are in lower or uppercase, while case insensitive applications do not care about that. Are search engines case sensitive? No, search engines do not distinguish between queries in lower and uppercase. One exception are Boolean operators.

Which database is 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.

Does case-sensitive matter in SQL?

Keywords in SQL are case-insensitive for the most popular DBMSs. The computer doesn't care whether you write SELECT , select, or sELeCt ; so, in theory, you can write however you like.


3 Answers

There are many examples of data with keys that are naturally case sensitive:

  • Files in a case sensitive filesystem like Unix.
  • Base-64 encoded names (which I believe is what YouTube is using, as in Artelius's answer).
  • Symbols in most programming languages.

Storing case sensitive data in case-insensitive system runs the risk of data inconsistency or even the loss of important information. Storing case insensitive data in a case sensitive system is, at worst, slightly inefficient. As you point out, if you only know the case-insensitive name of an object you're looking for, you need to adjust your query:

SELECT * FROM t WHERE LOWER(name) = 'something';

I note that in PostgreSQL (and presumably in other systems), it is a simple matter to create an index on the expression LOWER(name) which will be used in such queries.

like image 150
Edmund Avatar answered Sep 20 '22 12:09

Edmund


Depends on the data you want to store. Most UNIX filesystems are databases with case-sensitive keys. YouTube videos seem to be organised with case-sensitive keys.

Most of the time you want case-insensitive searches, but clearly there are certain exceptions.

like image 36
Artelius Avatar answered Sep 18 '22 12:09

Artelius


Use a case insensitive index for your field. In most cases you don't want to manipulate the data in order to find it.

like image 28
Gert Grenander Avatar answered Sep 20 '22 12:09

Gert Grenander