Paradoxical T-SQL

I’ve always taken comfort in the fact that T-SQL belongs to an enlightened age of computer languages in which the operations that were specified were close to real language. When one sees a command called DBCC_CHECKDB, then one could feel pretty confident that it checks your database for any problems. Or so I thought…until I discovered DBCC DBREPAIR.

If you’re feeling confident, without looking it up, that DBREPAIR will perform some sort of repair work on a damaged database, then you’re in for a shock. With an extraordinary irony, the command does the opposite of what you might think and destroys your database entirely. It is like using a Kalashnikov rifle to cure a headache.

The DBCC DBREPAIR command has been in SQL Server and Sybase from the start and one can still find the occasional forum reference to a time when it clearly did have some use for ‘repairing a database that had failed another DBCC check’. However, over time, the command was ‘simplified’ to the point where it meant ‘please drop my database from a great height’. Use it and you need never again worry about that torn page in your database!

Mercifully, the DBREPAIR command has been ‘repaired’ to the Grim Deprecator. However, its existence is a salutary lesson to all who are lulled into such a sense of confidence in the straightforward nature of T-SQL. When it lobs you a curve ball, it can have a devastating effect. And what next one wonders? What other tools and procedures could Microsoft provide to keep under-worked DBAs on their toes? Perhaps a DBCC CLEANTABLE command that relieves your database of its messy tables? Or a DBCC DBRECOVER command that pitches your healthy Database into ‘recovery mode’?

I planned to finish this editorial with further examples of amusingly paradoxical Transact SQL. However, it appears at this point as if some celestial DBA has mistakenly done a DBCC DBREPAIR on my brain, so consider it the Simple-Talk Christmas challenge. The best example of paradoxical T-SQL, added as a comment the editorial blog, will win a very nice iPod Nano.