MySQL/Bulk rename tablename: Unterschied zwischen den Versionen

Aus crazylinux.de
Zur Navigation springen Zur Suche springen
(init)
 
K (typo)
Zeile 9: Zeile 9:
<br>  
<br>  


<source lang="sql">select concat('rename 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
Zeile 19: Zeile 19:
Result:<br>  
Result:<br>  


rename nagios_acknowledgements to npc_acknowledgements;<br>rename nagios_commands to npc_commands;<br>rename nagios_commenthistory to npc_commenthistory;<br>rename nagios_comments to npc_comments;<br>rename nagios_configfiles to npc_configfiles;<br>
rename nagios_acknowledgements to npc_acknowledgements;<br>rename nagios_commands to npc_commands;<br>rename nagios_commenthistory to npc_commenthistory;<br>rename nagios_comments to npc_comments;<br>rename nagios_configfiles to npc_configfiles;<br>  


<br>


now run this commands in your sql-window


now run this commands in your sql-window
[[Category:Datenbank]] [[Category:Tips_und_Tricks]]


[[Kategorie:Datenbank]]
[[Kategorie:Datenbank]]
[[Kategorie:Tips_und_Tricks]]
[[Kategorie:Tips_und_Tricks]]

Version vom 5. März 2009, 21:15 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