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 表是否存在;句法?


- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01