【问题标题】:Counting MySQL tables always returns zero?计数 MySQL 表总是返回零?
【发布时间】:2016-03-11 13:13:23
【问题描述】:

我肯定遗漏了一些非常明显的东西,但我有这个非常基本的 MySQL 查询:

SELECT count(*) from information_schema.tables WHERE table_schema == "my_table";

但是,即使“my_table”存在,此查询也始终返回零。我在这里错过了什么?

【问题讨论】:

    标签: mysql count database-schema


    【解决方案1】:

    在特定模式(数据库)中搜索表。您必须在查询中提供 TABLE_SCHEMA

    SELECT count(*) from information_schema.tables where table_name = 'my_table' and table_schema = 'database_name'
    

    同时执行SELECT * from information_schema.tables,看看还有哪些信息表。

    【讨论】:

    • 双 = 运算符被错误地留在了,但添加 tale_schema 就可以了。 :)
    【解决方案2】:

    双重== 是问题所在。这不是 C/C++ :-)

    【讨论】:

      【解决方案3】:

      当我运行SELECT table_schema from information_schema.tables 时,它返回数据库名称,而不是表名称。

      【讨论】:

        【解决方案4】:

        在 where 条件下使用单个 = 运算符。试试这个查询

        SELECT count(*) from information_schema.tables WHERE table_schema = 'my_table';
        

        阅读它以获取更多信息Official Link

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-01-17
          • 2011-09-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多