salix/db/routines/vn2008/procedures/check_table_existence.sql

17 lines
502 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`check_table_existence`(IN table_name CHAR(64))
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' SET @err = 1;
SET @err = 0;
SET @table_name = table_name;
SET @sqlString = CONCAT('SELECT NULL FROM ',@table_name);
PREPARE stmt1 FROM @sqlString;
IF (@err = 1) THEN
SET @table_exists = 0;
ELSE
SET @table_exists = 1;
DEALLOCATE PREPARE stmt1;
END IF;
END$$
DELIMITER ;