patternsqlMajor
Modify all tables in a database with a single command
Viewed 0 times
tablesallwithdatabasesinglecommandmodify
Problem
Is there a single or a one line command to modify all tables within a database. I would like to issue this command in every table within a database:
My objective is to modify the charset from latin1 to utf8 to all tables.
UPDATE: RDBMS is MySQL
ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8;My objective is to modify the charset from latin1 to utf8 to all tables.
UPDATE: RDBMS is MySQL
Solution
No, there is no such command. But what you can do is write a quick query to generate the SQL for you like so:
Then you can run the output from this to do what you need.
Sources:
http://forums.mysql.com/read.php?20,244395,244421#msg-244421
USE INFORMATION_SCHEMA;
SELECT
CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` CONVERT TO CHARACTER SET UTF8;")
AS MySQLCMD FROM TABLES
WHERE TABLE_SCHEMA = "your_schema_goes_here";Then you can run the output from this to do what you need.
Sources:
http://forums.mysql.com/read.php?20,244395,244421#msg-244421
Code Snippets
USE INFORMATION_SCHEMA;
SELECT
CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` CONVERT TO CHARACTER SET UTF8;")
AS MySQLCMD FROM TABLES
WHERE TABLE_SCHEMA = "your_schema_goes_here";Context
StackExchange Database Administrators Q#35073, answer score: 24
Revisions (0)
No revisions yet.