HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

voluntarily produce an error with DBCC CheckDb

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
errorproducewithdbcccheckdbvoluntarily

Problem

Would anyone know how I can make DBCC CheckDB produce an error?
I'm testing a script and need DBCC Checkdb in the simplest mode to return an error, also while trying to repair and when trying to go into single user mode...

The simple dbcc checkdb command thant I'm using is part of a batch file and is as follows:

OSQL -S MYPC -E -d MyDB -l 10 -Q "DBCC CHECKDB(AG_DB_STORESQL)" -b -o c:\MyFolder\MSSQL_DB_CHECK.Log


If no errors are found the script ends. If errors are found, the script tries to fix them with the REPAIR_REBUILD option and if that fails the script tries to fix them with REPAIR_ALLOW_DATA_LOSS option. Obviously, before trying to Repair the script attempts to put the DB in Single user mode (which is also error trapped)

So All I'm looking for is a way to cause DBCC CheckDB to return an error.

Solution

Handy corruption demo script has been created by Paul Randal. These are really good and would help you a lot. Please browse below links

-
Corruption demo databases and scripts

-
Using DAC connection to fix corrupt system tables

-
Various SQL Server Database corruption scenarios

Context

StackExchange Database Administrators Q#135195, answer score: 5

Revisions (0)

No revisions yet.