How to automatically convert a MySQL column to lowercase

前端 未结 2 1839
滥情空心
滥情空心 2021-01-23 20:41

Is there a property that I can add to a column so that it converts its value to lowercase? Instead of doing it for every single value through PHP?

2条回答
  •  忘掉有多难
    2021-01-23 21:31

    You could probably do it through a trigger that fires on insert or update. Myself, I'd rather just create a view that has a lower-case version of the column in question. The SQL for the view might look like

    SELECT ID, LOWER(MY_COLUMN) AS MY_COLUMN_LOWERCASE
    FROM MY_TABLE;
    

提交回复
热议问题