过客
过客
Published on 2020-12-13 / 4 Visits
0
0

MySQL判断表是否存在

MySQL语句中

SELECT COUNT(*) FROM information_schema.TABLES WHERE table_name ='查询的表名';

存储过程中

DECLARE tableExists INT DEFAULT 0;

SELECT COUNT(*) INTO tableExists FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '查询的表名';
IF tableExists > 0 THEN
	-- 表存在
ELSE
	-- 表不存在
END IF;

Comment