Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many columns in a table? 2

Status
Not open for further replies.

innmedia

Programmer
Mar 24, 2000
108
US
Hi,

Is there any quick way to get a count of fields (columns) in a table?
 
select count(*)
from syscolumns c, sysobjects o
where o.name='TABLE_NAME' and c.id=o.id


Just replace TABLE_NAME with whatever.

TR
 
Another way is

Code:
Select
Count(Column_Name)
From INFORMATION_SCHEMA.COLUMNS
Where Table_Name = 'XXX"

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
MDXer's approach is better because the INFORMATION_SCHEMA view is supposed to be an abstraction layer and shield from the 'sys' tables so that Microsoft can change them at will. Of course, I think stuff would break all over the place if and when they did, but hey, we have been warned.

TR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top