Sunday, June 19, 2011

Count lines of code in a database

Here is a small script to count lines of code in a database:

    o.type_desc as ObjectType
    ,count(*) as [ObjectCount]
    ,sum(len(m.definition) - len(replace(m.definition, char(13), ''))) as [TotalLineCount]
from sys.objects o
inner join sys.sql_modules m on o.object_id = m.object_id
where o.[type] in ('P', 'TR', 'FN', 'IF', 'V', 'TF')
and not like 'aspnet[_]%'
and not like 'vw[_]aspnet[_]%'
group by o.type_desc
order by o.type_desc