<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DBCC WRITEPAGE &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/dbcc-writepage/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 02 Aug 2017 19:29:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: Corrupt a table using DBCC WRITEPAGE</title>
		<link>https://www.dbrnd.com/2017/08/sql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 09 Aug 2017 16:16:01 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[DBCC IND]]></category>
		<category><![CDATA[DBCC WRITEPAGE]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[suspect_pages]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5797</guid>

					<description><![CDATA[<div><img width="679" height="509" src="https://www.dbrnd.com/wp-content/uploads/2017/08/data-corrupt-679x509.gif" class="attachment-post-image size-post-image wp-post-image" alt="data-corrupt" decoding="async" fetchpriority="high" /></div>In this post, I am sharing a demonstration on how to damage a table of SQL Server. Why I am sharing this because practice on data corruption is required for SQL DBA before actual data corruption happens. You can find N number of different solutions for restoring corrupted database or table, but what about like [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="509" src="https://www.dbrnd.com/wp-content/uploads/2017/08/data-corrupt-679x509.gif" class="attachment-post-image size-post-image wp-post-image" alt="data-corrupt" decoding="async" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&amp;linkname=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&amp;linkname=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&amp;linkname=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&amp;linkname=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&amp;linkname=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&amp;linkname=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages%2F&#038;title=SQL%20Server%3A%20Corrupt%20a%20table%20using%20DBCC%20WRITEPAGE" data-a2a-url="https://www.dbrnd.com/2017/08/sql-server-corrupt-a-table-using-dbcc-writepage-suspect_pages/" data-a2a-title="SQL Server: Corrupt a table using DBCC WRITEPAGE"></a></p><p>In this post, I am sharing a demonstration on how to damage a table of SQL Server.<br />
Why I am sharing this because practice on data corruption is required for SQL DBA before actual data corruption happens.</p>
<blockquote><p>You can find N number of different solutions for restoring corrupted database or table, but what about like if you want to test any of this solution.<br />
In most of the cases, the table gets corrupt because of invalid data or junk data of data page. Using DBCC WRITEPAGE, you can modify the table page.</p></blockquote>
<p>Please check the below demonstration, and share your commands/options via comments to restore this table.</p>
<p><strong>Create a sample database:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE KillMe
GO 
USE KillMe 
GO</pre> </p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_bad
(
    ID INT IDENTITY(1,1) 
    ,Name VARCHAR(10) DEFAULT 'dbrnd'
)
GO 

CREATE CLUSTERED INDEX ix_ID ON tbl_bad(ID) 
GO
 
INSERT INTO tbl_bad DEFAULT VALUES
INSERT INTO tbl_bad DEFAULT VALUES
INSERT INTO tbl_bad DEFAULT VALUES
INSERT INTO tbl_bad DEFAULT VALUES
INSERT INTO tbl_bad DEFAULT VALUES 
GO</pre> </p>
<p><strong>Find the page information of table:</strong></p>
<pre class="crayon-plain-tag">DBCC IND (KillMe, 'tbl_bad', 1)
GO</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">PageFID PagePID     IAMFID IAMPID      ObjectID    PageType 
------- ----------- ------ ----------- ----------- -------- 
1       320         NULL   NULL        565577053   10       
1       312         1      320         565577053   1</pre> </p>
<p><strong>Change database to single user mode:</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE KillMe SET SINGLE_USER WITH ROLLBACK IMMEDIATE</pre> </p>
<p><strong>Modify page number which page type is 1:</strong></p>
<pre class="crayon-plain-tag">DBCC WRITEPAGE('KillMe', 1, 312, 60, 1, 0x00, 1)</pre> </p>
<p><strong>Now try to select your table data:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_bad</pre> </p>
<p><strong>Error in the result:</strong></p>
<pre class="crayon-plain-tag">Msg 824, Level 24, State 2, Line 1
SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0xe777b300; actual: 0xe777b303). It occurred during a read of page (1:312) in database ID 10 at offset 0x00000000270000 
in file 'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLSERVER\MSSQL\DATA\KillMe.mdf'.  Additional messages in the SQL Server error log or system event log may provide more detail. 
This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). 
This error can be caused by many factors; for more information, see SQL Server Books Online.</pre> </p>
<p><strong>Check the suspect_pages:</strong></p>
<pre class="crayon-plain-tag">SELECT * FROM [msdb].[dbo].[suspect_pages]</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">database_id file_id     page_id              
----------- ----------- -------------------- 
10          1           312</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
