Home > Query, SQL > BISQL # 92 – How to find Number of lines of Code in Database

BISQL # 92 – How to find Number of lines of Code in Database

Hi Friends,

In development fields we never know which different type of problem statement we may need to face , We just need to stay calm and focused and what client want and completing all of their requirement.

In one of my previous post we have already started analysing How to find Number of lines of Code in procedure or function , Now in this post we are covering for Calculating number of lines per Database is .

If you have miss the previous post then you can have continuity from that post where link is follows

:BISQL # 90 – How to find Number of lines of Code in procedure or function

image

We will use Adventure Works DB for this script

I have just tweaked query posted in above article and got desired result

--Total No of line of Code 
SELECT SUM(t.lines_of_code) - 1 AS 'Total No of Lines in code ' 
       
FROM
(
SELECT    o.name AS sp_name, 
       (LEN(c.text) - LEN(REPLACE(c.text, CHAR(10), ''))) 
        AS lines_of_code,
        CASE WHEN o.xtype = 'P' THEN 'Stored Procedure'
            WHEN o.xtype IN ('FN', 'IF', 'TF') THEN 'Function'
            END AS type_desc
FROM        sysobjects o
INNER JOIN    syscomments c
ON            c.id = o.id
WHERE        o.xtype IN ('P', 'FN', 'IF', 'TF')
            AND o.category = 0
            AND o.name 
            NOT IN ('fn_diagramobjects', 'sp_alterdiagram', 'sp_creatediagram', 
                    'sp_dropdiagram', 'sp_helpdiagramdefinition', 'sp_helpdiagrams',
                    'sp_renamediagram', 'sp_upgraddiagrams', 'sysdiagrams')
) t

Output of above query

image

We can use script as it is in your Database to get required result.

Hope you will like this post on How to find Number of lines of Code in Database .

If you really like reading my blog and understood at lest few thing then please don’t forget to subscribe my blog .

If you wan daily link and analysis or interesting link go to following website which will give @ your inbox please subscribe our following link resource blog

Where todays links are

Link Resource Website

You may also find following interesting post :

For More information related to BI World visit my Mentalist Blog

Link Resource Blog >> Daily Interesting links

SQL Server Mentalist >> SQL Learning Blog

Business Intelligence Mentalist >> BI World

Connect With me on

| Facebook |Twitter | LinkedIn| Google+ | WordPress | RSS |

Advertisement
Categories: Query, SQL
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: