MySQL 检查mysql中是否存在表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14129843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if table exists in mysql
提问by Kin
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. I do not need to create a table, and just need to check whether it exists or not.
PS我不需要创建表,只需要检查它是否存在。
回答by Jordi Kroon
Or you could use this (longer query).
或者你可以使用这个(更长的查询)。
SELECT count(*)
FROM information_schema.tables
WHERE table_schema = 'databasename'
AND table_name = 'tablename'
回答by bonCodigo
You could do the following:
您可以执行以下操作:
SHOW TABLES LIKE tablename;
As per OP's comment - Edit:
根据 OP 的评论 - 编辑:
Check the demo out. It shows a code like this:
查看演示。它显示了这样的代码:
SHOW TABLES LIKE 'user%';
Results:
结果:
TABLES_IN_DB_2_8B528 (USER%)
user_images
users