Check if MySQL table exists without using quot;select fromquot; syntax?(在不使用“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 表是否存在;句法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在不使用“select from"的情况下检查 MySQL 表是否存在;句法?


基础教程推荐
- 在多列上分布任意行 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01