Skip to content

Corruption

SQL Server Row Data Linking to Off Row Data

 

The question came up as how to find a link from blog storage that is corrupt back to the table and row that contains that data.

The is no link from the blob storage back to the table and row, but this is a link from the data page containing the table and row off to the blob data.

 

First let’s start with row data and off row data. When SQL Server stores a row that contains variable size data like a VARCHAR, if all the lengths of all the values in the row are less than about 8k, SQL Server stores that entire row in a single data page. If a row contains a set of data larger than 8K, then some if it can be moved off row and stored in blob storage.

Picture the following table:


CREATE table test1
 (
 ID INTEGER IDENTITY PRIMARY KEY CLUSTERED,
 bigVarchar1 varchar(max),
 bigVarchar2 varchar(max)
 );

If you were to put small values into the varchar columns then the entire row would fit in a single data page (8k). But if you put 4k of data into one varchar(max) and 8k of data into the next varchar(max) then it will not fit in a page. One of the varchar values will be moved off page into a page that contains blob storage. No rocket science here yet, but when you want to find the relationship between these page it gets difficult.

 


CREATE DATABASE blobTest;
GO
USE blobTest;
GO

CREATE table test1
(
 ID INTEGER IDENTITY PRIMARY KEY CLUSTERED,
 bigVarchar1 varchar(max),
 bigVarchar2 varchar(max)
);
GO
-- fits into a single page
INSERT INTO test1(bigVarchar1, bigVarchar2) VALUES ('test row ', 'test row ');

--SELECT * FROM test1;

DBCC IND('blobTest','test1',-1) WITH NO_INFOMSGS;

Using the undocumented DBCC IND command you can see that the table (clustered index) is comprised of 2 data pages, the first one of type 10 which is the IAM page or Index Allocation Map, and the secon page of page type 1 which is a standard data row.
<img class=”aligncenter size-large wp-image-6595″ src=”http://stevestedman.com/wp-content/uploads/rowData1-1024×82.png” alt=”” width=”605″ height=”48″ />

Next we add another row.

INSERT INTO test1(bigVarchar1, bigVarchar2) VALUES ('test row ', 'test row ');
DBCC IND('blobTest','test1',-1) WITH NO_INFOMSGS;

And we can see that both rows are still only using the same 2 pages.

Read More »SQL Server Row Data Linking to Off Row Data

The On Call DBA For Corruption

 

One of those services that I offer is on call help for DBA’s who encounter database corruption. Call me anytime 24/7 and as long as you are an existing customer, or we can work out a billing arrangement to turn you into a paying customer, I can help.

That’s all a good if you are familiar with what database corruption is. But based on the occasional phone call that I receive based on my outreach to help with database corruption, it makes me think that I haven’t done the best job describing what corruption is.

A few minutes ago at 12:15am, my phone rings, I was sound asleep but it woke me up and I answered it. Still a bit groggy I hear a voice on the other end asking “Are you the one who can help with database corruption removal?” to which I answer yes. He then goes into a story about how he has just been fingerprinted and he wasn’t supposed to be arrested. He goes on to describe how he didn’t feel that he should have been arrested, but the police officers have told him that now that his fingerprints are in the database, there isn’t anything they can do to undo it. I break in with “sorry that’s not the type of work I do”, and he continues to request my help to to get his fingerprints out of the database and remove his arrest record. I end the call, and hope that this wasn’t his one phone call that he is allowed when he was being booked.

Read More »The On Call DBA For Corruption