Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Code Objects Line Counter - SQL Server

RSS
Modified on Wed, Oct 22, 2008, 8:58 PM by Administrator Categorized as SQL Server
The following SQL statement will return a list of all code objects, along with the number of lines of T-SQL code for each.

with MyStats as (
select
     o.name
    ,o.type_desc
    ,o.type
    ,LineCount = len(m.definition) - len(replace(m.definition,char(13),''))
from 
    sys.objects o
    inner join sys.sql_modules m
        on o.object_id = m.object_id

where 1=1
    and o.name not like 'z[_]DeadCode[_]%'
    and o.name not like 'z[_]OldVersion[_]%'
    and o.name not like 'aspnet[_]%'
    and o.name not like '[_]%'
    and o.name not like 'fn[_]%'
    and o.name not like 'sp[_]%'
    and o.name not like 'vw[_]aspnet[_]%'
)
select 
    type_desc
    ,ItemCount = count(2)
    ,LineCount = sum(LineCount)
from 
    MyStats
group by 
    type_desc
order by 
    type_desc

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.