{"id":2953,"date":"2009-12-11T04:05:55","date_gmt":"2009-12-11T04:05:55","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/paradoxical-t-sql\/"},"modified":"2017-08-10T12:53:22","modified_gmt":"2017-08-10T12:53:22","slug":"paradoxical-t-sql","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/paradoxical-t-sql\/","title":{"rendered":"Paradoxical T-SQL"},"content":{"rendered":"<p>I&#8217;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&#8230;until I discovered DBCC DBREPAIR.<\/p>\n<p>If you&#8217;re feeling confident, without looking it up, that DBREPAIR will perform some sort of repair work on a damaged database, then you&#8217;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. <\/p>\n<p>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 &#8216;repairing a database that had failed another DBCC check&#8217;. However, over time, the command was &#8216;simplified&#8217; to the point where it meant &#8216;please drop my database from a great height&#8217;. Use it and you need never again worry about that torn page in your database!<\/p>\n<p>Mercifully, the DBREPAIR command has been &#8216;repaired&#8217; 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 &#8216;recovery mode&#8217;?<\/p>\n<p>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 <b>Christmas challenge<\/b>. The best example of paradoxical T-SQL, added as a comment the editorial blog, will win a very nice <b>iPod Nano<\/b>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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&#8230;until I&#8230;&hellip;<\/p>\n","protected":false},"author":200703,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,47125],"tags":[],"coauthors":[],"class_list":["post-2953","post","type-post","status-publish","format-standard","hentry","category-blogs","category-editorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/200703"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=2953"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2953\/revisions"}],"predecessor-version":[{"id":41829,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2953\/revisions\/41829"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=2953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=2953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=2953"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=2953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}