Home > Database > Mysql Tutorial > body text

How to Count Columns in a MySQL Table?

Patricia Arquette
Release: 2024-10-26 05:15:30
Original
229 people have browsed it

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'
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!