获取MySQL的列数

时间:2012-12-09 01:38:18

标签: mysql count

  

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

如何获取表格中的列数,搜索谷歌,但无法找到答案。

提前谢谢你。

2 个答案:

答案 0 :(得分:1)

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

此查询将为您提供列数。

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

答案 1 :(得分:0)

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