I have 100 tables, 40,000 rows in each table. I want to go into MySQL and delete all rows from all tables.
...in 1 statement, if p
DELIMITER $$
DROP PROCEDURE IF EXISTS `cleanAllTables`$$
CREATE DEFINER=`root`@`%` PROCEDURE `cleanAllTables`()
BEGIN
DROP Temporary TABLE IF EXISTS AllTables;
Create Temporary Table AllTables (
SELECT @curRow := @curRow + 1 AS row_number
, table_name
FROM INFORMATION_SCHEMA.tables s
JOIN (SELECT @curRow := 0
) r
WHERE s.table_schema = 'databasename');
set @countOfAllTables = (select count(*) from AllTables);
set @c = 1;
WHILE @c<=@countOfAllTables DO
set @table_name = (select table_name from AllTables where row_number = @c);
set @stmt = concat( 'Truncate Table ', @table_name);
Prepare stmt from @stmt;
Execute stmt;
SET @c = @c + 1 ;
END WHILE ;
END$$
DELIMITER ;