Script of the day: Count all objects in a database

Script of the day: Count all objects in a database

Rate This
  • Comments 4

This script counts all of your objects in the database, at least the ones stored in the sysobjects table. Some objects (such as jobs) don't show up there - one day I'll add those:

/*
usc_DBA_Count_Objects.sql
Author: Buck Woody
Purpose: Shows a quick count of database objects found in sysobjects */
SELECT 'Count' COUNT(*), 'Type' CASE 
type
                
WHEN 'C' THEN 
'CHECK constraints'
                
WHEN 'D' THEN 
'Default or DEFAULT constraints'
                
WHEN 'F' THEN 
'FOREIGN KEY constraints'
                
WHEN 'FN' THEN 
'Scalar functions'
                
WHEN 'IF' THEN 
'Inlined table-functions'
                
WHEN 'K' THEN 
'PRIMARY KEY or UNIQUE constraints'
                
WHEN 'L' THEN 
'Logs'
                
WHEN 'P' THEN 
'Stored procedures'
                
WHEN 'R' THEN 
'Rules'
                
WHEN 'RF' THEN 
'Replication filter stored procedures'
                
WHEN 'S' THEN 
'System tables'
                
WHEN 'TF' THEN 
'Table functions'
                
WHEN 'TR' THEN 
'Triggers'
                
WHEN 'U' THEN 
'User tables'
                
WHEN 'V' THEN 
'Views'
                
WHEN 'X' THEN 
'Extended stored procedures'
    
END
            
GETDATE
()
    
FROM 
sysobjects
    
GROUP BY 
type
    
ORDER BY 
type
GO

Leave a Comment
  • Please add 7 and 8 and type the answer here:
  • Post
Page 1 of 1 (4 items)