sys.dm_tran_version_store (Transact-SQL)


THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)yesAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Returns a virtual table that displays all version records in the version store. sys.dm_tran_version_store is inefficient to run because it queries the entire version store, and the version store can be very large.

Each versioned record is stored as binary data together with some tracking or status information. Similar to records in database tables, version-store records are stored in 8192-byte pages. If a record exceeds 8192 bytes, the record will be split across two different records.

Because the versioned record is stored as binary, there are no problems with different collations from different databases. Use sys.dm_tran_version_store to find the previous versions of the rows in binary representation as they exist in the version store.

Applies to: SQL Server (SQL Server 2008 through current version), SQL Database V12.

Column nameData typeDescription
transaction_sequence_numbigintSequence number of the transaction that generates the record version.
version_sequence_numbigintVersion record sequence number. This value is unique within the version-generating transaction.
database_idintDatabase ID of the versioned record.
rowset_idbigintRowset ID of the record.
statustinyintIndicates whether a versioned record has been split across two records. If the value is 0, the record is stored in one page. If the value is 1, the record is split into two records that are stored on two different pages.
min_length_in_bytessmallintMinimum length of the record in bytes.
record_length_first_part_in_bytessmallintLength of the first part of the versioned record in bytes.
record_image_first_partvarbinary(8000)Binary image of the first part of version record.
record_length_second_part_in_bytessmallintLength of the second part of version record in bytes.
record_image_second_partvarbinary(8000)Binary image of the second part of the version record.

On SQL Server requires VIEW SERVER STATE permission on the server.

On SQL Database Premium Tiers requires the VIEW DATABASE STATE permission in the database. On SQL Database Standard and Basic Tiers requires the SQL Database admin account.

The following example uses a test scenario in which four concurrent transactions, each identified by a transaction sequence number (XSN), are running in a database that has the ALLOW_SNAPSHOT_ISOLATION and READ_COMMITTED_SNAPSHOT options set to ON. The following transactions are running:

  • XSN-57 is an update operation under serializable isolation.

  • XSN-58 is the same as XSN-57.

  • XSN-59 is a select operation under snapshot isolation.

  • XSN-60 is the same as XSN-59.

The following query is executed.

    database_id rowset_id,  
  FROM sys.dm_tran_version_store;  

Here is the result set.

transaction_sequence_num version_sequence_num database_id  
------------------------ -------------------- -----------  
57                      1                    9             
57                      2                    9             
57                      3                    9             
58                      1                    9             
rowset_id            status min_length_in_bytes  
-------------------- ------ -------------------  
72057594038321152    0      12                   
72057594038321152    0      12                   
72057594038321152    0      12                   
72057594038386688    0      16                   
record_length_second_part_in_bytes record_image_second_part  
---------------------------------- ------------------------  
0                                  NULL  
0                                  NULL  
0                                  NULL  
0                                  NULL  

The output shows that XSN-57 has created three row versions from one table and XSN-58 has created one row version from another table.

Dynamic Management Views and Functions (Transact-SQL)
Transaction Related Dynamic Management Views and Functions (Transact-SQL)

Community Additions