TSQL Count Number Of Stored Procedures, Views, Tables or Functions
by Jon Hibbins on 4 September 2008
Filed under: Code, Database, MSSQL2005, MSSQL2008, SQL Server, Software Development, TSQL
You can use TSQL to Count Number Of Stored Procedures, Views, Tables or Functions in a Database by using the Database INFORMATION_SCHEMA view
/* Count Number Of Tables In A Database */ SELECT COUNT(*) AS TABLE_COUNT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' /* Count Number Of Views In A Database */ SELECT COUNT(*) AS VIEW_COUNT FROM INFORMATION_SCHEMA.VIEWS /* Count Number Of Stored Procedures In A Database */ SELECT COUNT(*) AS PROCEDURE_COUNT FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' /* Count Number Of Functions In A Database */ SELECT COUNT(*) AS FUNCTION_COUNT FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'
The same methodology can be used to query for information :
/* Select Table Information For A Database */ SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' /* Select View Information For A Database */ SELECT * FROM INFORMATION_SCHEMA.VIEWS /* Select Stored Procedure Information For A Database */ SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' /* Select Function Information For A Database */ SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'
March 10th, 2009 at 4:23 pm
Brilliant ,just what I needed to know.
July 31st, 2009 at 5:50 am
Excellent
August 27th, 2009 at 10:10 am
really nice work,
rajesh singh
October 27th, 2009 at 10:51 am
Great Job
November 17th, 2009 at 6:00 pm
Nice and Thanks. Just what I wanted.
January 13th, 2010 at 9:11 pm
Hello!
cialis , cialis , xanax , viagra , xanax ,
January 14th, 2010 at 9:22 am
thnx man…….
January 14th, 2010 at 4:07 pm
Hello!
cialis , cialis , phentermine , viagra , tramadol ,
January 17th, 2010 at 2:53 pm
Great ,
Thanks very Much
February 13th, 2010 at 5:07 pm
Hello!
tramadol , viagra , cialis , viagra , xanax ,
February 13th, 2010 at 5:16 pm
Hello!
viagra , buy cialis , cialis , viagra , viagra ,
February 14th, 2010 at 10:02 pm
Hello!
tramadol , phentermine , cialis , viagra , xanax ,
March 6th, 2010 at 4:47 pm
It is indeed helpful!!!!