Search code examples
mysqlalter-table

search simple way to alter multi tables in one time in mysql


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%'

Solution

  • 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.