How to Create a Corrupt SQL Server Database

  • Perry Whittle

    SSC Guru

    Points: 233859

    Comments posted to this topic are about the item How to Create a Corrupt SQL Server Database

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • MVDBA (Mike Vessey)

    SSC-Insane

    Points: 21757

    nice - not sure it's got too many practical implementations other than showing a junior how to run and correct checkdb, but it's still nice to have in your arsenal

    MVDBA

  • Perry Whittle

    SSC Guru

    Points: 233859

    Hi Michael, as the article mentions it's ideal for testing DBCC scripts against and also for practising dealing with a corrupt database.

    It also gives you an idea of what the data pages actually look like to

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • BenWard

    SSCertifiable

    Points: 5903

    Thanks - this would be a nice test for a practical interview if hiring for a DBA. Corrupt a bunch of things in advance and show the interviewee the DBCC CHECKDB results and see how many of them he/she can fix in 15 minutes.

    Ben

    ^ Thats me!

    ----------------------------------------
    01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
    ----------------------------------------

  • dioscoredes

    Old Hand

    Points: 361

    Really enjoyed the article. Thanks. Great demo for my advanced training labs. Have done this in Oracle several times and is interesting to see how SQL server pages map out by comparison. There are many more control fields in Oracle but the design drivers are exactly the same - how do you delploy object data into linear records in an ordinary file - and then how do you find that data. /BW/ PS. screwed up the feedback - sorry. Meant to be 5 stars, Idiot!

    Men who wish to know about the world must learn about it in its particular details. - Heraclitus
  • Geoff A

    SSChampion

    Points: 11417

    this is really good stuff. thank you.

    btw, this is also good for using to test a database mirror. i had to create a broken db once for testing failover. 😛

  • Perry Whittle

    SSC Guru

    Points: 233859

    dioscoredes (5/4/2012)


    Really enjoyed the article. Thanks. Great demo for my advanced training labs. Have done this in Oracle several times and is interesting to see how SQL server pages map out by comparison. There are many more control fields in Oracle but the design drivers are exactly the same - how do you delploy object data into linear records in an ordinary file - and then how do you find that data. /BW/

    Thank you for your feedback.

    For more info on in row and off row data in SQL Server see the following MS link

    dioscoredes (5/4/2012)


    PS. screwed up the feedback - sorry. Meant to be 5 stars, Idiot!

    LOL grr never trust an Oracle DBA 🙂

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • jfogel

    SSCarpal Tunnel

    Points: 4135

    michael vessey (5/4/2012)


    nice - not sure it's got too many practical implementations other than showing a junior how to run and correct checkdb, but it's still nice to have in your arsenal

    Maybe but it could be taken beyond just knowing to run DBCC commands. Back around 1999-2000 I had an issue similar to this but it would cause a query to fail and disconnect the session and of course, checkdb did fix it. The real challenge came when I was tasked with a root cause analysis. I thought by fixing it I was free and could move on. Not so, my boss wanted to know the how and why it happened. So perhaps this script and information are useful in that they could be helpful in developing investigative techniques.

    Cheers

  • iBar

    SSCertifiable

    Points: 5872

    Nice and simple. Thanks.

    Usually beginners comes on forum to find solution from experts and sometimes things are not meant for experts as such. However experts correction and appreciation makes them feel part of community.

    Good work.

    Cheers.

  • Andre Guerreiro

    SSCertifiable

    Points: 7319

    I loved this article. Very interesting to some of us who are learning the SQL Server internals and need to simulate disaster recovery.

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Perry Whittle

    SSC Guru

    Points: 233859

    Thanks for your feedback, please don't forget to rate the article to.

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • quackhandle1975

    SSChampion

    Points: 11055

    Five stars for me as I find this type of article almost a "reverse engineering" concept, sometimes this can help with the understanding.

    Good stuff.

    qh

    [font="Tahoma"]Who looks outside, dreams; who looks inside, awakes. – Carl Jung.[/font]
  • Perry Whittle

    SSC Guru

    Points: 233859

    hi thanks for your comments, hope you found it useful

    Regards Pez

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Database admin(DBA)

    SSCertifiable

    Points: 5373

    mY database will be corrupted [font="Arial"][/font].so how to recovery the corrupt database??????( i have little bit confusing.because of iam using below script reocvery the database :

    DBCC CHECKDB ('Corrupt2K8') WITH NO_INFOMSGS, ALL_ERRORMSGS

    exec sp_resetstatus 'Corrupt2K8'

    alter database Corrupt2K8 set emergency

    dbcc checkdb('Corrupt2K8')

    alter database Corrupt2K8 set single_user with rollback immediate

    dbcc checkdb('Corrupt2K8', REPAIR_ALLOW_DATA_LOSS)

    alter database Corrupt2K8 set multi_user ))

    NOTE: some points for consideration:

    Then restore My database from a backup - but make sure to run DBCC CHECKDB on that very backup to ensure it's not corrupt itself.

    DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS is the very last resort . Before that, you should restore a valid backup. Once you do use REPAIR_ALLOW_DATA_LOSS, don't expect your database to magically come back to life again - most likely, irreparable damage has occurred - especially in this case since it complains about system table corruption.

    Thank you in advance

    SQL server DBA

  • navneet.agarwal19

    SSC Enthusiast

    Points: 180

    Hi, It worked well but as I execute command to bring the database online after modifying the .mdf file. SQL Server throws an error:

    Msg 926, Level 14, State 1, Line 1

    Database 'Corrupt2K8' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information.

    Msg 5069, Level 16, State 1, Line 1

    ALTER DATABASE statement failed.

    Msg 5125, Level 24, State 2, Line 1

    File 'E:\SQL DATA\Corrupt2K8.mdf' appears to have been truncated by the operating system. Expected size is 524288 KB but actual size is 524280 KB.

    Msg 3414, Level 21, State 1, Line 1

    An error occurred during recovery, preventing the database 'Corrupt2K8' (database ID 10) from restarting. Diagnose the recovery errors and fix them, or restore from a known good backup. If errors are not corrected or expected, contact Technical Support.

Viewing 15 posts - 1 through 15 (of 26 total)

You must be logged in to reply to this topic. Login to reply