如何检测表是否存在? MySql [英] How do i detect if a table exist? MySql

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

问题描述

-edit- OMG小马回答正确。我不能接受他的回答,因为现在只是一个注释。

-edit- OMG Ponies answered this correctly. I cant accept his answer because for now it is just a comment.

我建议这样做

SELECT table_schema, table_name FROM information_schema.tables
WHERE table_schema = 'mydb' AND table_name='ApprovePost';

但这不可靠,导致我在windows和linux上的几个版本的mysql的错误

也许有其他方式。有人知道吗?

Maybe there is another way. Does anyone know?

这个问题是我可以做创建表如果不存在,但我做第二次传递添加FK约束。在我的sql转储我看到> 130包含在一个单一的表。该表只有6列,其中只有两个需要约束。

This issue is i can do create table if not exists but i do a second pass to add the FK constraint. In my sql dump i see > 130 contains on a single table. The table only has 6 columns, only two of these need constrains. The constrains keep building and building everytime i restart the apache server or whenever mono feels the need to call my global init method in my webapp.

推荐答案

每当我重新启动apache服务器或每当mono需要在我的webapp中调用我的全局init方法时,约束就会继续构建和构建。

看起来您需要使用 FLUSH TABLES 命令来输入INFORMATION_SCHEMA.TABLES以反映现有表格。

Looks like you need to use the FLUSH TABLES command for the INFORMATION_SCHEMA.TABLES to reflect existing tables.

参考:

  • TABLE CACHE

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

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