What is the meaning of Log Sequence Number? I know that it is of type binary and 10bytes long and it corresponds to the time the transaction happen in DB. But is this a high precision date-time value that is stored in some efficient binary format or is this a function of date-time and something else (for example the serial number of transactions that happen at the same milli second). I did a lot of searching but couldn't find a good answer to this.
Can any one explain with a formula or function that is used to derive the LSN from date-time or anything.
Every record in the SQL Server
transaction log is uniquely identified
by a log sequence number (LSN). LSNs
are ordered such that if LSN2 is
greater than LSN1, the change
described by the log record referred
to by LSN2 occurred after the change
described by the log record LSN.
From here.
You should not be concerned with how these are generated.
It is an increasing sequence (1,2,3,4,...), not a date time value. From the Microsoft documentation:
The log sequence number (LSN) value is
a three-part, uniquely incrementing
value. It is used for maintaining the
sequence of the transaction log
records in the database. This allows
SQL Server to maintain the ACID
properties and to perform appropriate
recovery actions.
There is no guaranteed way to derive it, but you can guess it from msdb.dbo.backupset
on the machine you did the backup on:
SELECT last_lsn
FROM msdb.dbo.backupset
WHERE backup_start_date = @backup_date
This is of course not exact and not reliable.
LSN is an auto-generated incremental number when transactions are committed and backup is done, so if you want to use that sequence to the application table use while loop in your to fetch the sequence and use the date -time values.