Reputation: 4944
I have the field below in a MySQL table. How can I force it to be in lower-case letters only?
`username` varchar(30) NOT NULL,
Upvotes: 3
Views: 6510
Reputation: 1882
You could use an 'before insert' trigger on the field you want to lowercased. More infos here : MySQL Trigger
(possible duplicate from here : mySQL phpmyadmin - lowercase data by default)
Upvotes: 1
Reputation: 1746
Rather then implementing it at application level you could write a database trigger that would change the content of the insert/update to lowercase as and when the insert/update happens, independent of the application.
Upvotes: 0
Reputation: 4157
In the database use the MySQL LOWER()
function around the inserts and/or the retrieval. You could also consider just doing it on the application side (meaning you still store the original...
Example
INSERT INTO mytable (username) VALUES(LOWER('TestUser'))
SELECT LOWER(username) FROM mytable
Upvotes: 4