In our development environment, we want to have a DeleteData.sql
query that developers can use to delete all of the data of all tables of all databases of their MariaDB docker instance.
For example, let's say our developers work on a project that has 3 databases:
- Accounts
- Products
- Orders
And let's say each database has 10 tables. We want to run DeleteData.sql
and delete data from all tables in these three databases.
We do this to give developers a tool to test different data sets both for performance testing and for data validation and consistency.
But we have no idea how we can achieve this. In SQL Server we would:
- Use a cursor to loop over databases
- Create delete statements for all tables of each database dynamically
- Use
execute sp_executesql
to run that query dynamically on that database
Is it possible in MariaDB? Is there a better way to get to this result?
CALL truncate_tables( someuser )
- to truncate all the tables.sp_executesql
, did you mean to tag your database system as such? If so, maybe you meantEXECUTE IMMEDIATE
?execute_immediate
is that it seems that it only works inside a stored procedure.