SQL语句实现:SELECT COUNT(*) FROM information_schema.`TABLES` WHERE TABLE_NAME=‘youTableName‘;
where子句中,表名是字符串类型,要加单引号。
MySQL存储过程中
函数实现:CREATE DEFINER = `root`@`localhost` FUNCTION `tableExists`(`tName` varchar(30))
RETURNS tinyint(4)
BEGIN
DECLARE tableExists TINYINT DEFAULT 0;
SELECT 1 INTO tableExists FROM information_schema.`TABLES` WHERE TABLE_NAME=tName;
RETURN tableExists;
END;