检查表是否存在于mysql中 [英] Check if table exists in mysql

查看:98
本文介绍了检查表是否存在于mysql中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
MySQL-检查表是否存在而不使用"select from"

Possible Duplicate:
MySQL - check if table exists without using "select from"

我可以依靠此查询来查找指定数据库中的表是否存在或可能存在一些限制吗?

Can I rely on this query to find out if tables in the specified database exists or there may be some restrictions?

SELECT
    `information_schema`.`TABLES`.`TABLE_NAME`
FROM
    `information_schema`.`TABLES`
WHERE
    `information_schema`.`TABLES`.`TABLE_SCHEMA` = 'my_database_name'
AND `information_schema`.`TABLES`.`TABLE_NAME` IN (
    'table_name',
    'table_name',
    'table_name',
    'table_name',
    'table_name',
    'table_name'
)

P.S. 我不需要创建表,只需要检查它是否存在.

P.S. I do not need to create a table, and just need to check whether it exists or not.

推荐答案

或者您可以使用它(更长的查询时间).

Or you could use this (longer query).

SELECT count(*)
FROM information_schema.tables
WHERE table_schema = 'databasename'
AND table_name = 'tablename'

这篇关于检查表是否存在于mysql中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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