0

Currently I have two procedures, one that passes the names of the tables into another procedure that will use the names to preform other tasks.

What I have: Used to pass table names to other function.

DELIMITER $$
CREATE PROCEDURE Save()
BEGIN
CALL OTHERPROCEDURE('Tablename1');
CALL OTHERPROCEDURE('Tablename2');
CALL OTHERPROCEDURE('Tablename3');
//etc...
END;
$$
DELIMITER ;

The issue I have is that at the moment I have only a few tables, which I can manually write in as shown above. However as more tables get introduced this becomes unpractical.

select table_name from information_schema.tables where table_schema = 'testdb';

So my idea was to use this select function that will return the names of all tables int he database testdb, then these name will then be passed into the procedure OTHERPROCEDURE one at a time. Although I know there are ways of doing this using the likes of PHP but I am trying to have it work solely with MySQL, if possible.

Is this even possible? If so how?

Evan
  • 288
  • 1
  • 10
  • 19
  • 2
    The thing you are looking for is a [cursor](https://dev.mysql.com/doc/refman/5.7/en/cursors.html), and [here](https://stackoverflow.com/q/4615193/6248528) a random example. – Solarflare Mar 05 '18 at 11:56
  • That exactly what I was looking for, thanks. – Evan Mar 05 '18 at 12:26

0 Answers0