Find the number of columns in a table

praveenjayapal picture praveenjayapal · Mar 18, 2009 · Viewed 398.5k times · Source

It is possible to find the number of rows in a table:

select count(*) from tablename

Is it possible to find the number of columns in a table?

Answer

Nathan Koop picture Nathan Koop · Mar 18, 2009
SELECT COUNT(*)
  FROM INFORMATION_SCHEMA.COLUMNS
 WHERE table_catalog = 'database_name' -- the database
   AND table_name = 'table_name'