Skip to main content

The most dangerous command in SQL

Vijay is a SQL Server/Microsoft Data Platform professional with over 10 years of experience working in various fields such as financial, healthcare, and Manufacturing Domains. He has worked in various DB-related roles from database Modeler to database developer to Data Warehouse.
the dangerous commend in SQL

The most dangerous command in SQL

There’s one command, in particular, that has been effectively hidden since it was introduced pre-SQL Server 2000.
I present to you DBCC WRITEPAGE ā€“ the most dangerous command you can use in SQL Server.
Well, no danger of death šŸ™‚
DBCC WRITEPAGE allows you to alter any byte on any page in any database, as long as you have sysadmin privileges. It also allows you to completely circumvent the buffer pool, in other words, you can force page checksum failures.
The purposes of DBCC WRITEPAGE are:
  1. To allow automated testing of DBCC CHECKDBand repair by the SQL Server team.
  2. To engineer corruptions for demos and testing.
  3. To allow for last-ditch disaster recovery by manually editing a live, corrupt database.

It’s not advised that you attempt #3 unless you’re confident you know what you’re doing and the side-effects on the Storage Engine from the byte(s) that you’re changing.
It is a very dangerous command because:
  1. It is an entirely physical change to the page – nothing is logged in the transaction log, and it cannot be rolled back.
  2. You can change any page in any database. For instance, you could use it to modify a page in master so that the instance immediately shuts down and will not start until the master is rebuilt and restored.
  3. Anyone with sysadmin privileges can use it and there is no way to stop it.
  4. It breaks the support of your database.

You can very easily shoot yourself in the foot very badly playing around with this command. This isn’t hyperbole – it’s just the truth.
dbcc WRITEPAGE ({ā€˜dbname’ | dbid}, fileid, pageid, offset, length, data [, directORbufferpool])
The parameters mean:
  • ā€˜dbname’ | dbid : self-explanatory
  • fileid : file ID containing the page to change
  • pageid : zero-based page number within that file
  • offset : zero-based offset in bytes from the start of the page
  • length : number of bytes to change, from 1 to 8
  • data : the new data to insert (in hex, in the form ā€˜0xAABBCC’ – example three-byte string)
  • directORbufferpool : whether to bypass the buffer pool or not (0/1)

DBCC WRITEPAGE does the following:
  • Checkpoints the database and flushes all its pages out of the buffer pool
  • Unhooks SQL Server’s FCB (File Control Block) from the data file
  • Creates its own FCB for the file
  • Does a direct read of the page into DBCC’s memory
  • Modifies the page directly
  • Writes the page directly to disk, bypassing the buffer pool and any page protection generation (i.e. not recalculating the page checksum)
  • Fixes up the FCBs again



The syntax is:
12
3
4
DBCC TRACEON (2588);GO
DBCC HELP (ā€˜WRITEPAGE’);
GO

If you’re going to play with it, please do not use it on a production system, and be very, very careful. It’s very easy to do something disastrous. And remember, if you use DBCC WRITEPAGE, you do so entirely at your own risk.

Comments

Popular posts from this blog

Best CSS frameworks for the Responsive site

CSS frameworks for the Responsive Website    One of the most popular and used web design tools is CSS, which powers the design and layout of a website. CSS frameworks are an important resource for web developers as they can be used to make designing websites easier. The five best CSS frameworks for 2022 are Bootliquor, The Grid System, UIkit, Foundation, and SemanticUI. Bootliquor: Bootliquor is a lightweight framework that provides tools to create responsive grid layouts and RTL language support for Arabic and Hebrew languages. The Grid System: This framework focuses on making it easier to design websites with templates that can be easily rearranged with drag-and-drop functionality. UIkit: Uikit is another responsive grid system that offers hundreds of pre-made templates as well as the ability One of the best ways to learn web development is to use a framework. Frameworks make it easy for developers to create and build websites and templates without writing every line of code...

Top 10 Mobile app development Management Tools

Top 10 Mobile app development Frameworks  The mobile app development has been one of the hottest topics in technology for quite some time now. There are many apps that are being developed by companies with all kinds of varied purposes. These include gaming, gaming, entertainment, productivity, research, and more. The increasing demand for different types of apps has led to an increase in the number of app developers. The problem is that it is difficult to find the best mobile app development, management tools to help them create all these apps. Mobile applications are software that is created to run on devices such as smartphones, tablets, or watches to perform various tasks. there are types various mobile applications such as email applications, gaming, application health applications, travel applications, banking applications, etc. These applications can be easily downloaded in applications distributed platforms such as the Apple app store or Google Play store. Mobile Application...

The Internet of Things It Cover All Business Web Services

The Source IoT, It will describe the market around the Internet of Things (IoT), the technology used to build these kinds of devices, how they communicate, how they store data, web services, cloud computing contributes to the growth of the internet of things from the mere definition to reality. ... Web service uses XML for data representation and data transportation between layers. Divided into four modules, we will learn by doing. We will start with simple examples and integrate the techniques we learn into a class project in which we design and build an actual out system. Internet of  Things Graph, a service that connects different devices and cloud services, such as linking humidity sensors to sprinklers to weather data services to create agricultural applications, Industrial apps through a visual drag-and-drop interface.  Internet of Things Site Wise to monitor operations across facilities, quickly compute common industry performance metrics, build applications t...