Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database

Count Lines of code in a database

5.00/5 (1 vote)
26 Apr 2010CPOL 13.2K  
Assuming that a carriage return represents a line of code, this will count the lines of code in a SQL 2008 database:SELECT ROUTINE_NAME,ROUTINE_TYPE,LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')) LOCFROM INFORMATION_SCHEMA.ROUTINESCOMPUTE...
Assuming that a carriage return represents a line of code, this will count the lines of code in a SQL 2008 database:

SQL
SELECT 
ROUTINE_NAME,
ROUTINE_TYPE,
LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')) LOC
FROM INFORMATION_SCHEMA.ROUTINES
COMPUTE SUM(LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')))
COMPUTE avg(LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')))

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)