Home  >  Article  >  Database  >  How Many Columns Does a MySQL Table Have?

How Many Columns Does a MySQL Table Have?

Barbara Streisand
Barbara StreisandOriginal
2024-10-25 21:22:28202browse

How Many Columns Does a MySQL Table Have?

Determining Column Count in MySQL Tables

Question:

How can I determine the number of columns in a given MySQL table?

Answer:

To count the columns in a MySQL table, you can use the following query:

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

Example:

Consider the following table named "tbl_info":

ID name age gender
1 John 15 Male
2 Maria 18 Female
3 Steph 19 Female
4 Jay 21 Male

To count the columns in this table, we would execute the following query:

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

This query would return the count of columns in the "tbl_info" table, which in this case is 4.

The above is the detailed content of How Many Columns Does a MySQL Table Have?. 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