
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to achieve case sensitive uniqueness and case insensitive search in MySQL?
You can achieve case sensitive uniqueness and case insensitive search with the help of the following two ways −
- VARBINARY data type
- _bin collation
VARBINARY data type
To work with the VARBINARY data type, let us first create a table. The query to create a table is as follows −
mysql> create table SearchingDemo2 -> ( -> UserId VARBINARY(128) NOT NULL, -> UNIQUE KEY index_on_UserId2(UserId ) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Query OK, 0 rows affected, 1 warning (0.99 sec)
Keep in mind UserId has data type VARBINARY(128) and Index(‘index_on_UserId2’) on a column ‘UserId’.
_bin collation
The second way is as follows. Let us create a new table −
mysql> create table SearchingDemo -> ( -> UserId varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, -> UNIQUE KEY index_on_UserId(UserId ) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Query OK, 0 rows affected, 2 warnings (0.88 sec)
UserId has data type varchar(128) and index(index_on_UserId) on a column ‘UserId’.
Both the above approach achieve case sensitive uniqueness and case insensitive search in MySQL.
- Related Articles
- Is Python case-sensitive or case-insensitive?
- Case insensitive search in Mongo?
- How to perform case-insensitive search in Oracle?
- MongoDB query with case insensitive search?
- MySQL case-insensitive DISTINCT?
- MongoDB query for specific case insensitive search
- How to use case-insensitive switch-case in JavaScript?
- Perform case insensitive SELECT using MySQL IN()?
- How to make SQL case sensitive string comparison in MySQL?
- Are MySQL database and table names case-sensitive?
- How MySQL can perform case-sensitive string comparison?
- How can I search (case-insensitive) in a column using LIKE wildcard?
- How do you force MySQL LIKE to be case sensitive?
- MongoDB $regex operator i or I for case insensitive search
- Case-insensitive Dictionary in C#

Advertisements