Pages

Sunday, 23 September 2012

How to get total no of Tables, Views, SP and Functions in SQL?


Use [Your_DB_Name]

/* Count Total Number Of Tables */
SELECT COUNT(*) AS 'Total Tables' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
   
/* Count Total Number Of Views */
SELECT COUNT(*)  AS 'Total Views'  FROM INFORMATION_SCHEMA.VIEWS
   
/* Count Total Number Of Stored Procedures */
SELECT COUNT(*)  AS 'Total SPs'  FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE'
   
/* Count Total Number Of UDF(User Defined Functions) */
SELECT COUNT(*)  AS 'Total Functions' FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'

Output:


No comments:

Post a Comment