How to Voluntarily Produce an Error with DBCC CheckDb

dbcc-checkdb

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.

Best Answer

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