If I know the database-name and table-name, how can I find columns-count of the table from sql server master database?
What is the fastest way to find the columns count of any database-table?
What do you think about the performance of this query?
select count(*) from SYSCOLUMNS where id=(select id from SYSOBJECTS where name='Categories')
I need to support sql server 2000 and onwards.
It may vary slightly depending on the version of SQL Server, but this will work for 2005:
In 2000:
If you might have multiple tables with the same exact table name under different owners then you’ll need to account for that. I forget the column name in sysobjects to look at off the top of my head.
UPDATE FOR NEWER VERSIONS OF SQL Server and ANSI compliance: