Update all values of a column to lowercase

Lets say I have something like 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?

102997 次浏览

LOWER()

update table set tag = LOWER(tag)

不区分大小写的匹配版本,如果不想更新整个列,可以包含“ WHERE”子句:

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

如果您的数据库使用不区分大小写的匹配,COLLATE 行将使其正常工作,就像我的数据库一样。

试试这个:

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