Search code examples
mysqlintegerenumerationalter

When you alter a table how do you detect the data type of columns?


I am running MySQL and I need to change the data type of certain columns from an enumeration to integer. However, there are a lot of columns. (If this exists) What is the syntax to alter all columns at the same time that are enumerations. Here is how I am updating a single column to make it integer data type:

ALTER TABLE table_name CHANGE column_name column_name INTEGER;

Solution

  • SHOW COLUMNS FROM WHERE TYPE LIKE "%enum%"

    you could afterwards iterate through your result similar to the solution described here: https://www.php.net/manual/en/function.mysql-fetch-field.php#92069 hope this helps, Michael