Home  >  Article  >  Database  >  How to Count Columns in a MySQL Table?

How to Count Columns in a MySQL Table?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-26 05:15:30231browse

How to Count Columns in a MySQL Table?

Counting Columns in a Table using MySQL

This article addresses the query of counting the number of columns within a MySQL table. Let's delve into how this can be achieved.

To determine the column count of a table named "tbl_ifo," follow this SQL statement:

SELECT count(*)
FROM information_schema.columns
WHERE table_name = 'tbl_ifo'

Let's break down this query:

  • SELECT count(*): This command counts the total number of rows, which corresponds to the number of columns in the table.
  • FROM information_schema.columns: The data is being sourced from the "columns" table within the "information_schema" database. This table stores metadata about tables, including information about columns.
  • WHERE table_name = 'tbl_ifo': This clause filters the data to only include the rows that have a table name equal to "tbl_ifo."

By executing this query, you will obtain a single row with a single column displaying the column count of the specified table.

The above is the detailed content of How to Count Columns in a MySQL Table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn