I have some schemas, all with the same format. The format is: schema name, underscore, single digit (example: database_1).
How can I loop through all of these schemas easily? I tried SET @num = 1; USE database_@num;
But it says
Unknown database 'database_@num'
I'm using MariaDB 10.1.30
Best Answer
The particular statement you want to run -
USE
- is not supported by dynamic SQL. I therefore suspect what you want to do is not currently possible.If dynamic SQL did support the
USE
statement, you could have done:MariaDB 10.1:
MariaDB 10.3:
Both result in:
The MariaDB knowledge base has a list of permitted statements that you can
PREPARE
. Effectively, this is a list of statements that can be used in dynamic SQL.EDIT:
So instead I suppose you're left with options such as:
SOURCE
that file.USE
statement, obviously.)