December 9, 2012

Get count of columns MySQL

Question by user1868569

How can i get the count of columns in my table, searched google through, but can’t find a straight answer.

Thank you in advance.

Answer by Starx

Such information are located in INFORMATION_SCHEMA you can query a table called COLUMNS to get the number of columns in a database.

This query will give you the column count.

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!