Home >Database >Mysql Tutorial >How Many Columns Does a MySQL Table Have?
How can I determine the number of columns in a given MySQL table?
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!