Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altering Mysql Table column to be case sensitive

Tags:

mysql

I have a table in my Mysql database, which is used for authentication. And now, I need to make the authentication case sensitive. Googling around, I have realized Mysql columns are case insensitive (contrary to Oracle) for search operations and the default behavior can be changed while creating the table by specifying the "binary" ie.

CREATE TABLE USERS (     USER_ID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,     USER_NAME VARCHAR(50) BINARY NOT NULL ) 

Can someone please tell me how to alter the table in Mysql to add the "Binary" to an existing column of a DB?

Thanks!

like image 837
PaiS Avatar asked Aug 03 '10 12:08

PaiS


People also ask

How do I make columns case sensitive in SQL?

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 a database or database object is by checking its “COLLATION” property and look for “CI” or “CS” in the result.

How do I make MySQL case sensitive?

It is important to note that MySql is not only case insensitive for columns using an _ci collation (which is typically the default), but also accent insensitive. This means that 'é' = 'e' . Using a binary collation (or the binary operator) will make string comparisons accent sensitive as well as case sensitive.

Are columns in MySQL are case sensitive?

Column, index, stored routine, and event names are not case-sensitive on any platform, nor are column aliases. However, names of logfile groups are case-sensitive. This differs from standard SQL. By default, table aliases are case-sensitive on Unix, but not so on Windows or macOS.

How do I create a like case-insensitive query in MySQL?

select * from users where lower(first_name) = 'ajay'; The method is to make the field you are searching as uppercase or lowercase then also make the search string uppercase or lowercase as per the SQL function.


1 Answers

ALTER TABLE USERS CHANGE USER_NAME USER_NAME VARCHAR(50) BINARY NOT NULL; 
like image 155
deinst Avatar answered Sep 21 '22 07:09

deinst