How to change case in each field of mysql table in one call?

I have a table with 27 varchar fields. I want to make all fields lowercase, but I want to do this with one short mysql call.

This makes one field:

UPDATE table
SET field = LOWER(field)

How to make the equivalent of this (which doesn't work):

UPDATE table
SET * = LOWER(*)
+5
source share
2 answers

You cannot do this with your creative effort SET * = LOWER(*), etc.

However, you can do it as follows:

UPDATE table SET
column1 = LOWER(column1),
column2 = LOWER(column2),
 -- etc, listing all text type columns
columnN = LOWER(columnN);

The reason there is no shortcut is probably because this template is so rarely needed.

+3
source

The consensus is that this cannot be done in a single mysql query.

PHP script, N ( @alex):

$sql = "SHOW COLUMNS
        FROM table";
$results = mysqli_query($dbcon,$sql);
while($column = mysqli_fetch_assoc($results))
{
    $column = $column["Field"];
    $sql = "UPDATE table
            SET $column = LOWER($column)";
    $success = mysqli_query($dbcon,$sql);
}
0

All Articles