Created
May 21, 2014 13:37
-
-
Save alisspers/e2d272bb31ffbc964362 to your computer and use it in GitHub Desktop.
Altering all tables in a database to change their collation can be a tedious task if needed on a large database. This nifty little trick based on a SO answer (http://stackoverflow.com/a/19462205) returns a list of all altercommands for the tables in a database, to make your life a bit easier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get a list of all ALTER commands needed to change collation on all tables in the given database | |
Note: Remember to set your database name on line 7, and change utf8_swedish_ci to the collation of your choice | |
Props goes to this answer on StackOverflow: http://stackoverflow.com/a/19462205 | |
*/ | |
SELECT CONCAT("ALTER TABLE `", TABLE_NAME,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_swedish_ci;") AS mySQL | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_SCHEMA="YOUR_DATABASE_NAME" | |
AND TABLE_TYPE="BASE TABLE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment