Skip to content

Instantly share code, notes, and snippets.

@timkeller
Created March 1, 2012 14:49
Show Gist options
  • Save timkeller/1950247 to your computer and use it in GitHub Desktop.
Save timkeller/1950247 to your computer and use it in GitHub Desktop.
Quick generator, in sql, to create ALTER sql instructions for a set of databases of the same schema on the same MySQL server
SELECT
CONCAT(
'ALTER TABLE `',
TABLE_SCHEMA,
'`.`',
TABLE_NAME,
'` ADD `change-field-name` VARCHAR(5) NULL DEFAULT NULL',
';'
) AS sql_string
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA LIKE "some-prefix-maybe_%" AND
TABLE_NAME = "change-table-name"
GROUP BY
TABLE_SCHEMA,
TABLE_NAME;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment