开发者

Update all values of a column to lowercase

开发者 https://www.devze.com 2023-03-09 09:28 出处:网络
Lets say I have something like 开发者_Go百科this uidtag 1HeLLo 2heLLO 3HELLO 4hello How can I update all values in the \"tag\" column to:

Lets say I have something like 开发者_Go百科this

uid    tag
1      HeLLo
2      heLLO
3      HELLO
4      hello

How can I update all values in the "tag" column to:

uid    tag
1      hello 
2      hello 
3      hello 
4      hello 

using MySQL?


See http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_lower

UPDATE table_name SET tag = LOWER(tag)


LOWER()

update table set tag = LOWER(tag)


Version for case-insensitive matching and including a "WHERE" clause if you don't want to update the entire column:

UPDATE table 
SET tag = LOWER(tag)
WHERE LOWER(tag) != tag
COLLATE Latin1_General_CS_AS

The COLLATE line will make it work if your database uses case insensitive matching, as mine does.


Try this:

update `table` set `column_name` = LOWER(column_name without quotation)
0

精彩评论

暂无评论...
验证码 换一张
取 消