DBCC CHECKDB and repair

Topic

When a database is corrupted, we will alwayssuggest restoring last known good database backup instead of running DBCCCHECKDB command to fix it. Can you explain why? Try to use a demo to show whyDBCC CHECKDB command is not always a first choice for a corrupted database.

 

Answer:

REPAIR_ALLOW_DATA_LOSS

·        The purpose of repair is not to save user data.The purpose of repair is to make the database structurally consistent as fast as possible(to limit downtime) and correctly (to avoid making things worse). 

·        This means that repairs have to be engineered tobe fast and reliable operations that will work in every circumstance. Thesimple way to do this is to delete what's broken and fix up everything thatlinked to (or was linked from) the thing being deleted - whether a record orpage.

·        This means that repairs have to be engineered tobe fast and reliable operations that will work in every circumstance. Thesimple way to do this is to delete what's broken and fix up everything thatlinked to (or was linked from) the thing being deleted - whether a record orpage.

·        Things to look for that mean repair won’t be ableto fix everything are:

    • CHECKDB stops early and complains about system table pre-checks failing (errors 7984 – 7988 inclusive)
    • CHECKDB reports any metadata corruption (8992, 8995 errors)
    • CHECKDB reports any errors on PFS page headers (8939, 8946 errors with a possible 8998 error as well)

Test1: Damage the data page

--create a test database

usemaster

createdatabase testcheckdb

usetestcheckdb

 

--create table t3

droptable t3

createtable t3

(

    c1 int primarykey,

    c2 nvarchar(50)

)

 

--insert a row (0, 'ABCDEFG')

select* from t3

insertinto t3 values(0,'ABCDEFG')

go

 

--insert 1000 rows

declare@count int

set@count = 1

WHILE@count <= 1000

   BEGIN

      insert into t3values(@count,'abc')

      set@count = @count+1

   END;

GO

 

--check data

select* from t3

--check page

dbcctraceon(3604)

DBCCind('testcheckdb', t3,-1)

--//154-IAMpage;155-index root page;153,156,157-data page

DBCCpage('testcheckdb', 1,154,3)--//

DBCCpage('testcheckdb', 1,155,3)--//

DBCCpage('testcheckdb', 1,153,3)--// m_slotCnt = 351


DBCCpage('testcheckdb', 1

你可能感兴趣的:(SQL,Server,allocation,object,table,database,sql,server,sqlserver)