SQL Server - Break database consistency

This is risky! Be aware of doing this on some production database. This script is published for training purposes only. Use it with caution, this will definitely break your database, and you can loose data.

I am using it to break database before DBCC CHECKDB and consistency errors fixing showcase.

-- Output the page summary for the clustered index on Person.Person in AdventureWorks2017 database (index id = 1)
DBCC IND (AdventureWorks2017, 'Person.Person', 1)
GO

-- You then pick some data page (PageType = 1) and write to it in single-user mode
ALTER DATABASE AdventureWorks2017 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
 
-- In this showcase page found is 1177
DBCC WRITEPAGE('AdventureWorks2017', 1, 1177, 60, 1, 0x00, 1)

ALTER DATABASE AdventureWorks2017 SET MULTI_USER

Related posts

Leave a Reply