Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Guest editorial: SQL Code Metrics

By Phil Factor,

SQL has a wonderful way of teaching us humility. Just when we think we have it sussed, we realise that there are better ways of doing it. I've never found a routine that can't be improved in some way; particularly in my own work. Writing good SQL code is a fascinating activity, a constant fight against hasty assumptions, outdated rules, and learned procedural programming practices. SQL is very different from any other type of programming.

This truth of this was brought home to me sharply the other day whilst reading about 'code smells' and quality metrics in C#. How wonderful it would be, I thought, if we could use the same techniques in order to detect 'smelly' SQL code in a database system. All we'd need to do is to check on the complexity of the code, the number of lines of code in a procedure, the number of SQL Statements, and possibly the complexity of the execution plan.

The only tool I've found that makes some of this available is SQLTAC. However, a lot more is attainable. For example, we could check for an over-reliance on cursors, the use of the * to insert into a table, the presence of SQL Statements that consistently take a long time to execute, code without comments or documentation, over-use of table variables, tables without a primary key, over-denormalized tables, and so on. It would be deeply satisfying to be able to produce a graphical representation of TSQL code quality, to wave in front of some poor programmer's face when you're checking his work!

Just as quickly as the thought had occurred to me, however, I dismissed it. The trouble is that when I supervise a programmer who is learning SQL, I sometimes learn new ideas that come from a fresh mind being applied to old problems. The code may, in general, stink, but the new ideas are priceless. If we apply 'quality metrics' and 'best practices' without applying our own judgement and intuition, we run the risk of ossifying rules that are merely intended to be guides. Code metrics are a good servant but a very poor master.

Phil Factor.

Total article views: 349 | Views in the last 30 days: 2
 
Related Articles
BLOG

Human Data Quality

Disclaimer: I read and speak one language, having failed pretty well at learning Latin, Spanish, and...

ARTICLE

Data Quality

Today we have an editorial reprinted from Dec 12, 2005 as Steve is on vacation. Steve talks about th...

ARTICLE

Tracking Business Metrics

There can be more to managing a SQL Server instance than just examining the performance metrics. The...

FORUM

OEM SQL Server Plug-in Metrics Monitoring Issues

OEM SQL Server Plug-in Metrics Monitoring Issues

FORUM

What's Your Code Quality?

I saw this Peter Coffee editorial on code quality, specifically Java development managers. I think...

Tags
editorial    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones