2

I have created a stored procedure that uses dbcc checkdb on all userdatabases, if there are any errors detected it then collates the errors and formulates a html table and sends an html email to myself, if there are no errors it sends an email with text along the lines of 'no integrity errors found'.

There are no integrity errors regarding the database and so it does indeed successfully send me an email saying 'no integrity errors found'.

Now I am trying to test the error detection and collation, and to do so I have to create ideally multiple integrity errors but am at a loss as to how to do this on purpose, can this be done?

P.S. I'm using SQL Server 2019

2

1 Answer 1

3

Use DBCC WRITEPAGE:

SELECT
    cmd = 
        N'DBCC WRITEPAGE (' + CAST(dddpa.database_id AS nvarchar(10)) + N', ' +
        CAST(dddpa.allocated_page_file_id AS nvarchar(10)) + N', ' +
        CAST(dddpa.allocated_page_page_id AS nvarchar(10)) + N', ' +
        N'0' + 
        N', ' + 
        N'4' + 
        N', ' + 
        N'0x0000008A' +
        N') WITH NO_INFOMSGS'
FROM sys.dm_db_database_page_allocations
    (
        DB_ID(), 
        NULL, 
        NULL, 
        NULL, 
        'DETAILED'
    ) AS dddpa;
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.