BISQL # 92 – How to find Number of lines of Code in Database
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
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
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
You may also find following interesting post :
- BISQL # 89 – How to establish / Find relationship between Table and stored Procedure in Database
- List of Monthly post of MS BI, SQL & Link Resource Blog – March 2012
- Free E-Book Microsoft for SQL Server 2012–Download, Information and Content
- BISQL # 88 – Laymen to SQL Developer # 8 – Assignment #1 – Part #7 – Explanation and Basic Theory for Codd’s Rules and Normalization
- BISQL # 87 – Why DB Diagram doesn’t Work !! OR How to enable Database Diagram
- BISQL # 86 – How to Run SSIS package in SQL Server using xp_cmdshell
- List of Monthly post of MS BI,SQL & Link Blog – January 2012
- BISQL # 85 – SQL SERVER – Interview Questions and Answers Book
- BISQL # 84 – How to select ALL tables or Select all Top rows in one script ? All data from all table !
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