Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL case sensitivity for primary key

Are MySQL primary key values case sensitive? If it's an option how do I set it? I want the table to be able to store "www.Example.com" and "www.example.com" as different values.

like image 993
Zach Avatar asked Mar 28 '13 16:03

Zach


People also ask

Is MySQL primary key case sensitive?

yes. ci is case insensitive.

Is primary key in SQL case sensitive?

In SQL Server, by default, primary keys are case-insensitive and when you transfer data from Oracle to SQL Server and then try to create the primary key constraints, you may have duplicate key errors.

How do you make a primary key case sensitive?

You can do this in SQL Server Management Studio via the Object Explorer by right-clicking on the database and going to "Properties > Options" then the "Collation" drop-down. Any one that has "CS" in the name is case-sensitive.

Can MySQL be case sensitive?

Table names are stored in lowercase on disk and name comparisons are not case-sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.


2 Answers

You can set per-column collations in MySQL: https://dev.mysql.com/doc/refman/5.5/en/charset-column.html

e.g. if your table is generally (say) case insensitive, you can override it per-field to be case-sensitive.

like image 88
Marc B Avatar answered Sep 26 '22 02:09

Marc B


The BINARY keyword will do the trick, though I'm not sure if it's the recommended way to do this:

CREATE TABLE testpk (MyPK VARCHAR(20) BINARY PRIMARY KEY NOT NULL)
like image 33
Ed Gibbs Avatar answered Sep 22 '22 02:09

Ed Gibbs