SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Zombie SQL

It Halloween so time for a scary SQL story. Ok, maybe not that scary. Ok, not scary at all, but still a bad practice. It’s Zombie code so it seemed like something fun to talk about on Halloween. But what is it?

Zombie Code

Code that is left in place but commented out.

At least that’s the best definition I was able to find. You’ve seen it right? Those big queries left in the stored procedure but commented out? Or lines of the WHERE clause commented out? Heck, I’ll bet you’ve done it. I know I have.

“I might need that code later.”
“That was pretty cool, I’ll save it so I can look at it again.”
“I just don’t like deleting code if I don’t have to.”
“It’s not working, I’ll comment it out and come back to it later.”

The problem is, zombie code is distracting. It makes it harder to read what’s actually going on, and as you learn to tune it out, you are also learning to tune out the real comments. And comments are important.

CREATE PROCEDURE ReallyImportantBatchProcess AS

SELECT ReallyImportantColumn1, ReallyImportantColumn2, 
	ReallyImportantColumn3, ReallyImportantColumn4
	INTO #ImportantToday
FROM ReallyImportantData
WHERE ImportantDate = Today;

                      /|x x|
                     /\( - )
            /=`_'-'-'/  !!
            |-{-_-_-}     !
            (-{-_-_-}    !
             \{_-_-_}   !
          ____%%@ @%%_______

-- [¬º-°]¬
ALTER TABLE #ImportantToday ADD Column Meh bit

UPDATE #ImportantToday SET Meh = 1 /* Did you see this? */
-- WHERE ReallyImportantColumn3 = 74

Now to be fair, when you are in the middle of development it can be perfectly reasonable to leave bits of code commented out. If it’s a personal script then I’d expect bits of commented code to expand the usefulness of the script. However, as code moves from development to test, and in particular when it moves past test into model office or even production, then all of that commented code should be removed. In the days of version control software, there is very little reason to leave bits of code commented out just so you can see them later and leaving code so it can be uncommented to add functionality shouldn’t be happening in production. The only comments that you want to leave in your code are the important ones. The ones that actually add value. That way when people scan the code, the comments jump out, they aren’t just part of the hoard of zombies.

Happy Halloween


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.


Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...