MySQL/Bulk rename tablename: Unterschied zwischen den Versionen
< MySQL
Zur Navigation springen
Zur Suche springen
K (typo) |
(higlighting) |
||
Zeile 1: | Zeile 1: | ||
Sample: | Sample: | ||
DB=nagiostest | DB = nagiostest | ||
tablenames = nagios_foo | tablenames = nagios_foo | ||
Zeile 10: | Zeile 10: | ||
<source lang="sql">select concat('rename table nagios_',table_name,' to npc_',table_name,';') as cmd from ( | <source lang="sql">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 | 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</source> | where table_name like 'nagios_%' and `TABLE_SCHEMA` = 'nagiostest') as foo</source> | ||
<br> | <br> | ||
Result:<br> | Result:<br> <source lang="sql"> | ||
rename nagios_acknowledgements to npc_acknowledgements; | |||
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;</source> | |||
now run this commands in your sql-window | now run this commands in your sql-window | ||
[[Category:Datenbank]] [[Category:Tips_und_Tricks]] | [[Category:Datenbank]] [[Category:Tips_und_Tricks]] | ||
Aktuelle Version vom 10. Juni 2009, 20:59 Uhr
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
Result:
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;
now run this commands in your sql-window