Skip to main content

Dangerous command in SQL

SQL Server/Microsoft Data Platform professional with over 10 years of experience working in various fields such as financial, healthcare, and Manufacturing Domains. we have worked in various DB-related roles from database Modeler to database developer to Data Warehouse.

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 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.
bcc WRITEPAGE ({‘dbname’ | dbid}, filed, 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.
Dangerous command in SQL

Comments

Popular posts from this blog

Top 5 AI Trends Transforming Software Development in 2024

  The landscape of software development is constantly evolving, and Artificial Intelligence (AI) is at the forefront of this change. In 2024, AI is poised to have an even greater impact on the way we build software, fundamentally shifting workflows and unlocking new possibilities. Let’s explore the top 5 AI trends shaping the future of software development 1. Generative AI Revolutionizes Code Creation: What it is:  Imagine an AI that can write code based on natural language descriptions or even automatically generate entire applications. This is the promise of Generative AI, and it’s rapidly evolving. Tools like LaMDA and GitHub Copilot are already showing capabilities beyond code completion, suggesting entire functions and algorithms. Impact:  This technology has the potential to significantly increase developer productivity, allowing them to focus on higher-level design and logic rather than repetitive coding tasks. Additionally, it could democratize software development, making it m

Which should Choose my Business Custom Software or SaaS

Custom software and SaaS are both good for different reasons. For example, if your company has a specific need then you should use custom software development. However, if you have a smaller budget or want to focus on your core business then you should use SaaS. Custom software is the best option when it comes to developing a new product or service. It is also better for companies that have specific needs and can't find the right solution in an existing product. On the other hand, SaaS is more affordable than custom software because it's already been developed by someone else and can be used by any company with a small budget. Custom software development is a more expensive way to develop software. It takes time and money to create, but the benefits are that it can be tailored to the needs of your business and it can be updated quickly if needed. SaaS has a monthly fee, but it is much cheaper than custom software development. The downside is that you are stuck with the features

App trends in AI, Machine learning, Security and Policy in 2023

 App trends in AI, Machine learning, Security, and Policy  The application of AI, machine learning, and custom software development is rapidly changing the way businesses operate. With the help of these technologies, companies can now create applications that are tailored to their specific needs. This allows them to remain competitive and stay ahead of their competitors. AI, machine learning and custom software development can also help businesses in terms of security and policy. By using these technologies, companies can develop applications that are secure and compliant with existing regulations. This helps them protect their data from potential threats while ensuring that they are following all applicable laws and regulations. AI, Machine Learning, and Security are some of the hottest topics in the tech world today. With the rapid advancements in these fields, custom software development companies are now able to create applications that can provide more efficient solutions for busi