T-SQL Count of Tables, Views, Stored Procedures and Functions
Posted by: Jason N. Gaylords Blog,
on 29 Oct 2013 |
View original | Bookmarked: 0 time(s)
Have you ever needed to obtain a list or count of all tables, views, stored procedures, and functions in a database? Its quite easy. Simply copy the T-SQL from below to a query window, set the desired database and execute.
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
SELECT * FROM INFORMATION_SCHEMA.VIEWS
SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE'
SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'
This will produce four result sets that will list the tables, views, stored procedures and functions. You can simply update the select statements with the keyword count to grab the count of each object if thats all you are looking for.