To get total number of columns in a table in sql

Viewed 186057

I need a query in sql to get total columns in a table.Can anybody help?

11 Answers

To get the list of all columns of the SQL table

   select column_name from information_schema.columns where table_name=[dbo].[your_table_name]

To get the list of number of columns of the SQL table

    select count(column_name) from information_schema.columns where table_name=[dbo].[your_table_name]
   

To get the total number of columns in table.

SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';
Related