Roll back transactions in the transaction log file

Source: Internet
Author: User
Tags how to use sql server how to use sql

Question: How to Use Transact-SQL to roll back a transaction in the transaction log file (for example, Id 0000: 0010a183 )?

Answer:: To prevent data errors, SQL server does not support rollback of individual transactions. For example, assume that two transactions t1 and t2 use the cash balance domain. $500 is added for T1, and T2 performs an operation using the updated value. If T1 is rolled back, T2. However, you can use timestamps or transaction log tags to restore logs to predefined tags or time points. The following two examples illustrate how to use SQL Server 2000 syntax.

Example 1: Use a timestamp to restore a log at a time point

Use the previous full backup to restore the database and make it ready for log recovery.

Restore database pubs from disk = n'c: \ Backups \ fullbackup. Bak 'with norecovery

Now you can roll logs to the appropriate time point and make the database available. Note that stopat cannot be executed when the database is executing large-capacity logs.

Restore log pubs from disk = n'c: \ Backups \ logbackup. Bak' with recovery, stopat = '2017/24/60 17:35:00'

Example 2: statements that use database tags to restore logs to a predefined time point

Add a tag to the transaction log. Note that at least one update must be submitted for the marked transaction to mark the log.

Begin Tran mymark with Mark
Update pubs. DBO. lastlogmark set marktime = getdate ()
Commit Tran mymark

Back up transaction logs according to your common methods.

Backup log pubs to disk = 'C: \ Backups \ fullbackup. Bak' with init

Now you can restore the database to a log mark point. First, recover the database and make it ready to accept log recovery.

Restore database pubs from disk = n'c: \ Backups \ fullbackup. Bak 'with norecovery

Now, the log is restored to the time point that contains the mark and made available for use. Note that stopat cannot be executed when the database is executing large-capacity logs.

Restore log pubs from disk = n'c: \ Backups \ logbackup. Bak' with recovery,
Stopat = '2014/1/0 17:35:00'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.