在不使用“select from"的情况下检查 MySQL 表是否存在;句法? [英] Check if MySQL table exists without using "select from" syntax?

查看:43
本文介绍了在不使用“select from"的情况下检查 MySQL 表是否存在;句法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查表是否存在而无需从中选择和检查值?

Is there a way to check if a table exists without selecting and checking values from it?

也就是说,我知道我可以去 SELECT testcol FROM testtable 并检查返回的字段数,但似乎必须有更直接/优雅的方法来做到这一点.

That is, I know I can go SELECT testcol FROM testtable and check the count of fields returned, but it seems there must be a more direct / elegant way to do it.

推荐答案

如果要正确,请使用 INFORMATION_SCHEMA.

If you want to be correct, use INFORMATION_SCHEMA.

SELECT * 
FROM information_schema.tables
WHERE table_schema = 'yourdb' 
    AND table_name = 'testtable'
LIMIT 1;

或者,您可以使用 SHOW TABLES

SHOW TABLES LIKE 'yourtable';

如果结果集中有一行,则表存在.

If there is a row in the resultset, table exists.

这篇关于在不使用“select from"的情况下检查 MySQL 表是否存在;句法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆