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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need script to show all objects in db

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
Does anyone have a script that will show a count of all object types in a database ?
eg

Tables 99
Indexes 33
Constraints 4
Views 6
...

 
Something like this should suffice. I'm not sure what the "D" object type is on sysobjects :-(

set nocount on

select case type
when 'D' then 'Whats This?'
when 'P' then 'Stored Procs'
when 'R' then 'Rules'
when 'S' then 'System Tables'
when 'TR' then 'Triggers'
when 'U' then 'Tables'
when 'V' then 'Views'
else 'Other'
end, count(*)
from sysobjects
group by type

select 'Indexes', count(*)
from sysindexes

select 'Constraints', count(*)
from sysconstraints

Greg.
 
Here's the SQL for the full list of object types in sysobjects ...

set nocount on

select case type
when 'D' then 'Default'
when 'L' then 'Log'
when 'P' then 'Procedure'
when 'PR' then 'Prepare Object'
when 'R' then 'Rule'
when 'S' then 'System Table'
when 'TR' then 'Trigger'
when 'U' then 'User Table'
when 'V' then 'View'
when 'RI' then 'Referential Constraint'
when 'XP' then 'Extended Stored Procedure'
end, count(*)
from sysobjects
group by type

select 'Indexes', count(*)
from sysindexes

select 'Constraints', count(*)
from sysconstraints

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top