Wednesday, February 25, 2009

SQL Server - Finding count of columns in a table

Gurus,

Please find the below code snippet to find the count of columns present in a table:

This SQL Server query will help us to find the count of columns present in the table. Here I am taking example of Northwind database Categories table. Which will give answer as '4' by default.

use Northwind
go
select count(*) 'Columns Count' from SYSCOLUMNS
where id=(select id from SYSOBJECTS where name='Categories')
go

Happy Coding Gurus!!!
HRK

No comments:

Post a Comment