SQLServerCentral Editorial

How to lay out SQL Code

,

Anyone who inherits a database application dreads poorly laid-out SQL code. Development teams loathe it. Putting it right would be easier, if there was a common, agreed, standard in place, so why the difficulty?

In my years as a technical book editor, my life was ruled by Strunk&White, and various other tomes on writing style and grammar. I understand more than most the importance of applying clear and consistent style to the written word, and yet I was a keen defender of the author's, often highly non-standard, "voice"; when the rules get too rigid it's all too easy to sap the life and personality out of a piece of writing

It seems that the same streak of individualism persists with the styling of SQL code. Every point – from use lowercase vs. camelCase vs. PascalCase, to naming standards, to the number of tabs (tabs? No way! Spaces!) to indent – is argued and debated, and everyone has their own set of preferences. Red Gate's SQL Refactor product offers over 40 different options for laying out SQL code and yet the feedback the developers get is that this just isn't enough!

Individual style is all well and good when it comes to SQL laying out code, but this isn't necessarily aligned with the goal of making the design and intent of your code as readily apparent as possible to other members of your team. Also, as any regular users of the SQLServerCentral forums will attest, you are much likely to make yourself understood, and therefore be helped, if the code you present on the forums is readable.

In my recent blog on simple-Talk, I suggested that, overall, it might help if the standard were tightened up a bit. I'd be interested to hear what Database Weekly readers think about this. Is it important that we arrive at some sort of layout standard, or doesn't it really matter as long as a developer keeps it simple and consistent? If you think a little more "uniformity" would help, what elements would you like to see in this new standard?

A $50 Amazon voucher goes to the best contribution, as judged partially, and in a non-standard fashion, by me.

Thanks to all who contributed to my "Jérôme Kerviel" editorial on 2nd Feb. The winner of the $50 Amazon voucher on that occasion was Matt Miller!

Cheers,

Tony Davis.

Guest Editor

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating