MySQL/Bulk rename tablename
Aus CrazyLinux
< MySQL
Sample:
DB = nagiostest
tablenames = nagios_foo
new tablename = npc_foo
SELECT concat('rename table nagios_',table_name,' to npc_',table_name,';') AS cmd FROM (
SELECT mid(table_name,8,length(table_name)-7) AS table_name FROM information_schema.TABLES
WHERE table_name LIKE 'nagios_%' AND `TABLE_SCHEMA` = 'nagiostest') AS foo
SELECT mid(table_name,8,length(table_name)-7) AS table_name FROM information_schema.TABLES
WHERE table_name LIKE 'nagios_%' AND `TABLE_SCHEMA` = 'nagiostest') AS foo
RENAME nagios_acknowledgements TO npc_acknowledgements;
RENAME nagios_commands TO npc_commands;
RENAME nagios_commenthistory TO npc_commenthistory;
RENAME nagios_comments TO npc_comments;
RENAME nagios_configfiles TO npc_configfiles;
RENAME nagios_commands TO npc_commands;
RENAME nagios_commenthistory TO npc_commenthistory;
RENAME nagios_comments TO npc_comments;
RENAME nagios_configfiles TO npc_configfiles;
now run this commands in your sql-window



