Wednesday, 22 May 2013

Code Horrors

I just stumbled across a strange piece of code, albeit a small one. I thought I would create a blog post to start collecting these gems.
 
Item 1
 
SELECT
    @RowIndex = RowID
FROM
    CBT
WHERE
    RowID = 1;
 
which actually means
 
SELECT @RowIndex = 1;
 

Monday, 20 May 2013

Fixing Database Corruption in a VLDB

A client of mine phoned me last week with an error message that had appeared in their application. My worst fears were confirmed when I heard the words "logical consistency-based I/O error".

The error message reported was:
SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0x31b2521f; actual: 0x4bd50f4c). It occurred during a read of page (3:8191715) in database ID 17 at offset 0x00000f9fdc6000 in file 'C:\MSSQL\Data\Data2.ndf'.  Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.