July 25, 2003 at 7:12 am
Hi,
is there a way to get the count of fields in a table? I have few tables in the database which contains about 65 fields or more. It's a pain to go through each field one by one to count them. There has to be a more efficient way to deal with this.
Thank you,
Ammad
~~~~~~
July 25, 2003 at 9:45 am
select si.name, count(*)
from syscolumns sc
inner join sysobjects so on so.id = sc.id
inner join sysindexes si on si.id = so.id
where si.indid < 2
and so.type = 'u'
group by si.name
having count(*) > 10
The HAVING clause is optional, just allows you to filter out tables with less than a specific number of columns
--
HTH,
Jay
July 25, 2003 at 9:47 am
To get a list of the columns in a specific table:
declare @TableName varchar(150)
--
select sc.*
from syscolumns sc
inner join sysobjects so on so.id = sc.id
inner join sysindexes si on si.id = so.id
where si.indid < 2
and so.type = 'u'
and si.name = @TableName
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply