Update all values of a column to lowercase

后端 未结 4 865
情书的邮戳
情书的邮戳 2021-01-30 10:18

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\" c

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 10:27

    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.

提交回复
热议问题