How to find columns count of any table in any database from sql server master database? -


If I know the database-name and table-name, how can I get the column count of the table from the SQL Server Master Am databases?

What is the fastest way to find column numbers in a database table?

What do you think about the performance of this query? Select Select from SYSOLUMNS (*) where id = (choose ID from SYSOBJECTS where name = 'categories')

I want to use SQL Server 2000 And then there is a need to support.

It may vary slightly depending on the version of SQL Server, but it will work for 2005 :

  from SELECT COUNT (*) & lt; Database Name & gt; .sys.columns WHERE Object_ID = OBJECT_ID ('& lt; Database name & gt ;.; & lt; owner & gt;. & Lt; table name & gt;')  

In 2000:

  SELECT COUNT (*) to & lt; Database Name & gt; .ysysobjects o Inner Join & lt; Database Name & gt; .syscolumns c ON.c. = O.id WHEREO.name = '& lt; Table name & gt; '  

If you have multiple tables with different table names, then you will need an account for this.

SQL Server and Update for new versions of ANSI compliance:

  select COUNT (*) I forgot the column name in sysobjects to see from above my head. From & lt; Database Name & gt; INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = '& lt; Table schema & gt; ' AND TABLE_NAME = '& lt; Table name & gt; '  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -