SHOW TABLES & SQL_CALC_FOUND_ROWS

SHOW TABLES & SQL_CALC_FOUND_ROWS

am 23.01.2006 01:23:35 von Larb

Good morning

I wish to do the following:

1. return an integer (0 or 1) whether a table exists in the database
otherwise I will create the table


Problem: instead of returning an integer I am being returned the "table
name" if it exists, or a NULL.

Now I understand that I need to use "SQL_CALC_FOUND_ROWS" but I am
unsure of how to implement that here.

Can anyone help ?

Thank you

Peter




My code so far:

DELIMITER $$;

DROP PROCEDURE IF EXISTS `Research`.`spTableExists`$$

CREATE PROCEDURE `spTableExists`(tableName varchar (5))
BEGIN
DECLARE MyTable VARCHAR(512);

SET @MyTable = concat('SHOW TABLES FROM MyDatabase LIKE ',"'",
tableName, "%'");

PREPARE stmt1 FROM @MyTable;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;

SELECT FOUND_ROWS();

END$$

DELIMITER ;$$