Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michabbb/f276153111da00932b75a04d6a9f2d78 to your computer and use it in GitHub Desktop.
Save michabbb/f276153111da00932b75a04d6a9f2d78 to your computer and use it in GitHub Desktop.
Helper SELECT: Changing FLOAT to DECIMAL in MySQL
SELECT
CONCAT('ALTER TABLE `',c.TABLE_NAME,'` CHANGE COLUMN `',c.COLUMN_NAME,'` `',c.COLUMN_NAME,'` ',REPLACE(c.COLUMN_TYPE,'float','decimal'),' ',IF(c.COLUMN_DEFAULT='NULL','DEFAULT NULL',' NOT NULL'),';')
FROM information_schema.COLUMNS c
WHERE c.TABLE_SCHEMA = 'mydatabase'
AND c.COLUMN_TYPE LIKE 'float%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment