Overview
As many organizations use SQL Server database to maintain their huge amount of data, it is very much necessary to be able to deal with the corruption cases in SQL Server effectively. Let us suppose that there is a corrupt page in SQL Server database. Restoring the complete database for one corrupt page in the database is not a clever thing to do. Instead, we should find a solution, which can restore the page from the most recent database backup. In the blog, we will provide the solution on how to perform page level restore operations in SQL Server without any data loss.
Steps involved in Page Level Restore Operations
The users of SQL Server can use RESTORE DATABASE Command, which has an optional parameter, which instructs it to only restore one/more pages, instead of the entire database. It is helpful, when the user needs to deal with a few pages, which have been corrupted by the problems related to IO subsystem. Let us understand the steps involved in Page Level Restore Operation:
1. Keep SQL Server database into SINGLE_USER mode. We can keep the database to RESTRICTED_USER mode, but the end users or Applications connected, using logins that map to db_owner role will be able to connect to the database. Due to this, single user mode is taken and the query Window used to set this mode should not be closed. The command, given below, will be used to set the database to single user mode-
- ALTER DATABASE <DBNAME> SET SINGLE_USER
- WITH ROLLBACK AFTER 15 SECONDS
- GO
In the command, given above, WITH ROLLBACK AFTER n SECONDS option is used to end connections or on-going operations.
2. In the second step, we will start the recovery process by taking backup of the tail end of the log file or the portion of the log file, which was not backed up. We will use the command, given below-
- BACKUP LOG DBNAME
- TO DISK = N ‘E: \SQLBACKUPS\DBName_TailEnd.trn’
- GO
Note: This option is critical as it is used to make sure that all the operations up to a certain point have been accounted for. Before performing this operation, the database should be set to single user mode; else, it will miss some operations.
3. We will run the RESTORE DATABASE command with the PAGE switch and all the pages, which needs to be restored. It is necessary to start the operation with last FULL backup. Using the commands stated below, we will perform the restore operation-

Join the conversation! Your thoughts help the community grow.