Recall the process a bit, when the pages are already in memory and the respective changes are made in terms of data, SQL Server writes in the transaction log the changes made by the transaction, this writing if it is on disk, that is, the pages are modified in memory, but the transaction log is modified on disk, once the writing in the transaction log has been made, the database only informs the user that the transaction has been confirmed. Then when the server is turned on after the database has been closed incorrectly, SQL Server runs a recovery process for each of the databases, which first makes a “Rollforward” and then a “Rollback” , after this the information remains in a consistent state.
A “Rollforward” is a process by which SQL Server reads the transaction log and begins to apply each and every one of the changes made to the pages of the database after the last checkpoint. At this point it does not matter if the transaction has been confirmed or rejected, simply apply all the changes.
Then in the “Rollback” process, SQL Server begins to rollback all transactions that were not confirmed in addition to those that were rejected, thus leaving the database in a consistent state.
This recovery process in some cases may take a long time due to the large amount of information that they have to replicate from the transaction log. That is why the frequency with which checkpoints are made within the database is crucial for the time it takes for the server to execute the recovery process.
Additionally it is worth mentioning that in a few occasions the termination of the SQL Server service unexpectedly can cause corruptions of data, and this is serious because in some cases the information may be recoverable, but always with a risk of losing some of the information. data, and in others it is not possible to fix the database, then the only thing that remains in these situations is the restoration of backups and that is where if you have a good backup strategy you can get to recover all the information until the moment of the disaster.
Well this has been a brief explanation in what refers to the recovery process that runs on the database server every time the service shuts down in an incorrect way.