Thursday, April 21, 2022

SQL Server: get count of tables, views, stored procs, etc

NOTE: the sys is not in master, but in msdb.  So the full name would be:

   SELECT count(name) as spcount FROM msdb.sys.sysobjects WHERE xtype = 'P'

or

select * from [servername\instance].msdb.sys.sysobjects 


===========================


SELECT count(name) as tablecount FROM sys.sysobjects WHERE xtype = 'U'


Below query will return the total number of views in sql server


SELECT count(name) as viewscount FROM sys.sysobjects WHERE xtype = 'V'



Below query will return the total number of stored procedures in sql server



SELECT count(name) as spcount FROM sys.sysobjects WHERE xtype = 'P'



Below query will return the total number of functions in sql server



SELECT count(name) as fncount FROM sys.sysobjects WHERE xtype = 'FN'


SELECT name FROM sys.sysobjects WHERE xtype = 'U'

SELECT name FROM sys.sysobjects WHERE xtype = 'V'

SELECT name FROM sys.sysobjects WHERE xtype = 'P'

SELECT name FROM sys.sysobjects WHERE xtype = 'FN'

No comments: