I’m new to mysql. I have this stored procedure where this procedure is to do the comparison between Max(id) and the Count(id) for all the tables in the database
CREATE PROCEDURE test5()
BEGIN
DECLARE Count INT DEFAULT 0;
DECLARE RC INT DEFAULT 0;
DECLARE MCC DOUBLE DEFAULT 0;
SET @tables = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=''test'' AND TABLE_TYPE=''BASE TABLE''';
SET MCC = (SELECT COUNT(TABLE_NAME) FROM (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'test' AND TABLE_TYPE = 'BASE TABLE') AS COUNT);
/*SET RC = 1;*/
SET Count = 0;
WHILE Count <= MCC
DO
SET @sql = 'SELECT DISTINCT Count(Id) AS "TOTAL_COUNT_ID", Max(id) AS "MAX_ID", (CASE WHEN Max(id) = Count(Id) THEN ''TRUE'' ELSE ''FALSE'' END) AS "RESULTS" FROM ' + @tables;
PREPARE test FROM @sql;
EXECUTE test;
SET Count = Count + 1;
END WHILE;
END
I manage to create this stored procedure but when calling this procedure it returns some syntax error which I could not find any when inspecting the query.