Search code examples
mysqlcase-sensitive

Is data stored in tables case sensitive?


I have three table samples. I have used mysql to store data in database

+--------------------------+
| Table-1                  |
+--------------------------+
| Sl.No | Name | City      |
+-------+------+-----------+
|  1    | Carl | Australia |
+-------+------+-----------+

+--------------------------+
| Table-1                  |
+--------------------------+
| Sl.No | Name | City      |
+-------+------+-----------+
|  1    | carl | australia |
+-------+------+-----------+

+--------------------------+
| Table-1                  |
+--------------------------+
| Sl.No | Name | City      |
+-------+------+-----------+
|  1    | CARL | AUSTRALIA |
+-------+------+-----------+
  • clearly we can see one row of data in each table
  • nature of data is same

what I have done is I have used different case letters some are uppercase letters and some are lowercase letters.

Are data stored in database case sensitive?


Solution

  • yes, the database stores the data how you submit it.

    if you say:

    INSERT INTO MyTable (LowerCase, UpperCase) VALUES ("abcd", "ABCD");
    

    it will insert:

    LowerCase | UpperCase
    abcd      | ABCD
    

    if you do

    INSERT INTO MyTable (LowerCase, UpperCase) VALUES ("AbCd", "aBcD");
    

    it will insert:

    LowerCase | UpperCase
    AbCd      | aBcD
    

    it's up to you to sanitize the inputs to the case you want, or just let it go as entered.

    however, when I do a

    SELECT * FROM MyTable WHERE LowerCase="abcd";
    

    it will return both entries.