views:

27

answers:

3

i have a lot of tables that start with some prefix ,

and i want to alter this tables

what is the simple way to do this (instead run over all tables)

i mean something like :

ALTER TABLE  LIKE tablenameprefix% ADD INDEX `NewIndex1` (`field`);

how can i do this ?

thanks

EDIT :

can i do a kind of loop not in stored procedure ? by select the names of tables from

SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE 'tableprefix%'
+1  A: 

You can't. What you could do though is write a stored procedure that enumerates all tables looking for your prefix and performs the necessary changes.

Adrian Grigore
+1  A: 

You would have to write a loop, according to the documentation you just specify the table name.

Dennis Haarbrink
+1  A: 

Given that ALTER TABLE syntax doesn't allow multiple table names, you cannot do this. You need to go through all tables in turn:

ALTER [IGNORE] TABLE tbl_name
alter_specification [, alter_specification]

Link: http://dev.mysql.com/doc/refman/5.0/en/alter-table.html

Anax