
Transact-SQL Syntax for Restoring to an LSN
By using a RESTORE statement, you can stop at or immediately before the LSN, as follows:
-
Use the WITH STOPATMARK = 'lsn:<lsn_number>' clause, where lsn:<lsnNumber> is a string that specifies that the log record that contains the specified LSN is the recovery point.
STOPATMARK roll forwards to the LSN and includes that log record in the roll forward.
-
Use the WITH STOPBEFOREMARK = 'lsn:<lsn_number>' clause, where lsn:<lsnNumber> is a string that specifies that the log record immediately before the log record that contains the specified LSN number is the recovery point.
STOPBEFOREMARK rolls forward to the LSN and excludes that log record from the roll forward.
Typically, a specific transaction is selected to be included or excluded. Although not required, in practice, the specified log record is a transaction-commit record.
For more information about how to use LSNs, see Log Sequence Numbers and Restore Planning.
For more information about point-in-time restores, see Restoring a Database to a Point Within a Backup.