DELIMITER //
CREATE PROCEDURE CountRowsInTables()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE tableName VARCHAR(255);
DECLARE rowCount INT;
DECLARE totalRows INT DEFAULT 0;
DECLARE cur CURSOR FOR
SELECT table_name
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name IN ('cities', 'iot_age_groups', 'iot_avatars', 'iot_chat_topic', 'iot_class', 'iot_coaching_points', 'iot_coaching_points_values', 'iot_csv', 'iot_days', 'iot_drills', 'iot_drills_categories', 'iot_drills_equipments', 'iot_drills_tactical_objectives', 'iot_drills_technical_objectives', 'iot_emailer_template', 'iot_equipments', 'iot_feedback_questions', 'iot_game_formation', 'iot_global_components_categories_master', 'iot_global_components_master', 'iot_global_components_tests_master', 'iot_logger_routes', 'iot_macrocycles', 'iot_matches_cards', 'iot_matches_color', 'iot_matches_formats', 'iot_menu', 'iot_mesocycles', 'iot_mesocycles_days', 'iot_mesocycles_days_drills', 'iot_mesocycles_days_drills_groups', 'iot_notifications_master', 'iot_notifications_master_templates', 'iot_notifications_method', 'iot_program_master', 'iot_roles', 'iot_roles_access', 'iot_school_menu', 'iot_school_roles', 'iot_school_roles_access', 'iot_school_sub_menu', 'iot_season', 'iot_sport', 'iot_sport_primary_positions', 'iot_sports_component_categories_master', 'iot_sports_component_categories_objectives', 'iot_sports_component_master', 'iot_sports_component_tests_master', 'iot_sports_positions', 'iot_star_track', 'iot_submenu', 'iot_submenu_child', 'iot_user_type', 'iot_users', 'iot_zipdetails', 'states');
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
read_loop: LOOP
FETCH cur INTO tableName;
IF done THEN
LEAVE read_loop;
END IF;
SET @sql = CONCAT('SELECT COUNT(*) INTO @rowCount FROM ', tableName);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET totalRows = totalRows + @rowCount;
SELECT tableName AS TableName, @rowCount AS RowCount;
END LOOP;
CLOSE cur;
SELECT 'Total' AS TableName, totalRows AS RowCount;
END //
DELIMITER ;
`CALL CountRowsInTables();
when I call this getting this error
Static analysis:
1 errors were found during analysis.
Missing expression. (near “ON” at position 25)
SQL query: Copy Edit Edit
SET FOREIGN_KEY_CHECKS = ON;
MySQL said: Documentation
#2014 – Commands out of sync; you can’t run this command now`