Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:28:00+00:00 2026-05-27T23:28:00+00:00

I have a table with a field a using encoding utf8 and collation utf8_unicode_ci:

  • 0

I have a table with a field a using encoding utf8 and collation utf8_unicode_ci:

CREATE TABLE dictionary (
    a varchar(128) NOT NULL
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The collation utf8_unicode_ci is required for an efficient case insensitive search with extensions and ligations. For this purpose i have the index:

CREATE INDEX a_idx on dictionary(a);

Problem: Additionally i must ensure that all stored values of the field a are unique but in a case sensitive way.
German example: “blühen” and “Blühen” must both be stored in the table. But adding “Blühen” a second time should not be possible.

Is there a build-in functionality in MySQL to have both?

Unfortunately it seems not to be possible to set the collation for the index in MySQL 5.1.

Solutions to this problem include a uniqueness check before insert or a trigger. Both are far less elegant than using a unique index.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:28:00+00:00Added an answer on May 27, 2026 at 11:28 pm

    Well, there are 2 ways to accomplish this:

    1. using _bin collation
    2. change your datatype to VARBINARY

    Case 1: using _bin collation

    Create your table as follows:

    CREATE TABLE `dictionary` (
     `a` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
     UNIQUE KEY `idx_un_a` (`a`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    

    Please note:

    1. the datatype of the column a
    2. the UNIQUE index on column a

    Case 2: using VARBINARY dataype

    Create your table as follows:

    CREATE TABLE `dictionary` (
     `a` VARBINARY(128) NOT NULL,
     UNIQUE KEY `idx_uniq_a` (`a`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    

    Please note:

    1. the new datatype VARBINARY
    2. the UNIQUE index on column a

    So, both the above will solve your purpose. That is, they both will allow values like ‘abc’, ‘Abc’, ‘ABC’, ‘aBc’ etc but not allow the same value again if the case matches.

    Please note that giving an “_bin” collation is different than using the binary datatype. So please feel free to refer to the following links:

    1. The BINARY and VARBINARY datatypes
    2. The _bin and binary Collations

    I hope the above helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a table field named 'description', what would be the SQL (using
I'm using SQL Server 2005 express I have a datetime field in a table
I have a table with a quick edit function (updates only one field using
I am using cakephp with php, I have table with field id having data
I have a mysql table field set as time type which stores data in
I have a table with one field that can point to a foreign key
I have a table with a field where words are written separated with new
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have table with an auto-increment field, but I need to transfer the table
I have table 'products' and I need to update 'price' field by 20% if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.