Editorials

Things that Make You Say ‘Icky’

Things that Make You Say ‘Icky’

I once won second place in a contest; but, never wanted to tell anyone about it. That was because it was a contest for the worst SQL code. Second place was so bad it was worth $100. I wonder what the $500 first place code looked like.

“What was bad enough to win $100”, you may ask? In this case, a stored procedure consisting of a single query that, when printed out, was 49 pages long. The sheer volume of the query made it difficult to follow the logic being solved.

This query was based on a system that only used views. None of the views were based on a single table. Sometimes there were views made from other views. So, I broke down the query to determine how many times each table was referenced, and found one table that was referenced 70 times. There are a lot of programmers out there a lot smarter than I am. So it’s nice to come across something once in a while to boost your ego. I was able to replace this stored procedure with three pages of code that performed in seconds instead of minutes. It was even more fun to take the team out to lunch, and then share with them how I paid for it.

So what do you take home from this little rant? Not $100 I’m sorry to say. I’m sure you have seen SQL code that makes you say “Icky”. Stored Procedures or functions are often written that do too much. Cursors are abused because procedural code is easier than set logic.

I have seen one system that used only one input parameter for all stored procedures; Params AS XML. I asked them why they had chosen this pattern. Their response was so they would have a single method in their database communication layer that worked for all stored procedures. It required no maintenance if parameters changed. While true, what they really did was break the ability to validate dependencies between the code calling the stored procedure, and the interface (input parameters) of the stored procedure. They didn’t reduce the code they had to write to implement database calls. They just made it more difficult to test the code they had written.

I can feel an article coming. But, before I do, let me give you a chance to say, “Icky”. Why not share your “Icky” experiences with us here at SSWUG. Drop a note to me, btaylor@sswug.org. I’ll see what patterns emerge, and we can all learn from the experience. Perhaps, as we share, there will be less Icky code in the world.

Featured Article(s)
Questions You Need to be Ready to Answer
Don’t forget that the technical part of the interview is only a portion of the interview. Most of the times it is just as important that you do well on the non-technical questions.