When you enable snapshot isolation on an Azure SQL Database, it does not create a true database snapshot, but rather a logical snapshot of the data. Enabling snapshot isolation in AzureSQL does not create a physical database snapshot. Instead, it maintains a logical snapshot of the data within the transaction log and tempdb to provide a consistent view for transactions. The resources used for snapshots are automatically managed and released when the transaction completes. Basically, when you enable snapshot isolation using the ALTER DATABASE
command, it enables a specific isolation level for transactions accessing the database. It does not create a physical snapshot of the entire database, instead when a transaction runs under snapshot isolation:- It sees the data as it existed at the start of the transaction, even if other transactions have modified the data since then.
- The database engine keeps track of the changes made by active transactions to allow this consistent view.
- Committed changes from other transactions are visible, but uncommitted changes are not.
Where are the Snapshots getting stored?
The data required to provide the consistent view is stored in the database itself, specifically in the transaction log and tempdb database.
Snapshot Lifecycle:
Snapshots are maintained until the transaction that requested the snapshot completes. Once the transaction commits or rolls back:
- The changes made by the transaction are committed or rolled back in the database.
- The resources used to maintain the snapshot are released and can be reused by other transactions.