【问题标题】:Get count of columns MySQL [duplicate]获取列数 MySQL [重复]
【发布时间】:2012-12-09 01:38:17
【问题描述】:

可能重复:
Find the number of columns in a table

如何获取表格中的列数,通过谷歌搜索,但找不到直接答案。

提前谢谢你。

【问题讨论】:

    标签: mysql count


    【解决方案1】:

    此类信息位于INFORMATION_SCHEMA中,您可以查询名为COLUMNS 的表以获取数据库中的列数。

    此查询将为您提供列数。

    SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
    WHERE table_schema = 'DB_NAME' AND table_name = 'TABLE_NAME'
    

    【讨论】:

    • 谢谢,效果很好:)!
    【解决方案2】:
    select COUNT(*) totalColumns
    from information_schema.columns
    where table_schema = 'db_2_a3c3e' AND -- the name of your Database
          table_name = 'table1'           -- the name of your table
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      相关资源
      最近更新 更多