Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Return a count of tables and fields within

Author  Topic 

davidliv
Starting Member

45 Posts

Posted - 2003-12-19 : 17:43:05
I need to create a query which will count all the tables in my database and the number of fields per table.

Can someone point me in the right direction?

Thanks,
-david

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-12-19 : 18:19:58
How's this:


select Name, (select count(*) from syscolumns where id = sysobjects.id) AS NumColumns from sysobjects where type = 'U' order by name


Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-12-20 : 03:20:36
Look at the documentation on INFORMATION_SCHEMA.COLUMNS in the Books Online. Michael's solution will work, but it's better to avoid querying the system tables directly.

Owais

We make a living out of what we get, but we make a life out of what we give.
Go to Top of Page
   

- Advertisement -