测试表的存在性

时间:2013-11-12 22:40:51

标签: mysql if-statement

在我的SQL脚本中,如何测试数据库中是否存在表?我想做类似以下的事情:

IF EXISTS test4 THEN 
  GRANT DROP ON test4 FOR 'root'@'localhost;
  DROP test4;
ENDIF

2 个答案:

答案 0 :(得分:1)

没有必要检查表格是否存在赠款 - 假设您甚至需要它们。

GRANT DROP ON test4 FOR ?
DROP test4 IF EXISTS

答案 1 :(得分:0)

如果您确实需要添加支票,可以使用系统目录

select table_name from information_schema.tables 
where table_name='TABLENAME' and table_schema='DBNAME'