Explain the Recovery model in SQL Server.
Explain the Recovery model in SQL Server
11015-Jul-2024
Updated on 17-Jul-2024
Home / DeveloperSection / Forums / Explain the Recovery model in SQL Server
Explain the Recovery model in SQL Server.
Ashutosh Kumar Verma
17-Jul-2024SQL Server recovery model
The recovery model is a property of a SQL database. The recovery model controls the following:
SQL Server uses the model database to set the default recovery model in the newly created databases.
Let's use the current database
Create a new table
People
in theMyCollegeDb
databaseNow, Insert some values into
People
table,View the Recovery Model
To view the recovery model of the current database in SQL server,
Also, you can see all the recovery models of all the databases in the SQL Server,
Change recovery model
To change the recovery model to another, you use the following
ALTER DATABASE
statement.Syntax-
Specify the recovery model name after the
SET RECOVERY
keyword. The recovery model can be one of these,SIMPLE
,FULL
, andBULK_LOGGED
.The following example changes the recovery model of the
MyCollegeDb
database from FULL to SIMPLE.Types of Recovery Models in SQL Server
There are three type of recovery model provided by SQL server,
Simple Recovery Model
In the
SIMPLE
recovery model, SQL Server deletes transaction logs from the transaction log files at every checkpoint.In the
SIMPLE
recovery model, transaction logs do not store transaction records, so you cannot use advanced backup strategies to minimize data loss. This results in relatively small transaction log files.Use the
SIMPLE
recovery model for databases whose data can be reloaded from other sources.Full Recovery Model
In the
FULL
recovery model allows you to restore the database at any point in time. In this recovery model, SQL Server keeps transaction logs in transaction log files until aBACKUP LOG
statement is executed means that theBACKUP LOG
statement deletes the transaction logs from the transaction log files.If you do not run the
BACKUP LOG
statement regularly, SQL Server stores all transaction information in the transaction log file until the transaction log is completed and the database is inaccessible, therefore you need to run theBACKUP LOG
statement at regular intervals to prevent the transaction log files from becoming full.BULK_LOGGED return pattern
The
BULK_LOGGED
recovery model has almost the same behavior as theFULL
recovery model except forbulk-logged
performance. For example, theBULK INSERT
of the flat file containing the tables is summarized in transaction log files.The
BULK_LOGGED
recovery model will never allow you to restore the database. A usefulBULK_LOGGED
relief scenario is the following,BULK_LOGGED
FULL
Also, Read: How to create user-defined role in SQL Server Database?