MySQL/Bulk rename tablename: Unterschied zwischen den Versionen

Aus crazylinux.de
Zur Navigation springen Zur Suche springen
(init)
 
(higlighting)
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 1: Zeile 1:
Sample:  
Sample:  


DB=nagiostest  
DB = nagiostest  


tablenames = nagios_foo  
tablenames = nagios_foo  
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
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;<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_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  


[[Kategorie:Datenbank]]
[[Category:Datenbank]] [[Category:Tips_und_Tricks]]
[[Kategorie: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