如何检测表是否存在? MySql

编程入门 行业动态 更新时间:2024-10-26 06:32:32
本文介绍了如何检测表是否存在? 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
  • TABLE CACHE

更多推荐

如何检测表是否存在? MySql

本文发布于:2023-10-24 17:28:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否存在   MySql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!