Understanding what the WITH ROLLBACK IMMEDIATE does

Published On: 2009-09-24By:

Based on some questions on forums and some of the responses that people have been giving there appears to be done misunderstanding about what the WITH ROLLBACK IMMEDIATE option does when added to the ALTER DATABASE command.  My goal here is to try and clear up at least some of the confusion.

When you run the ALTER DATABASE command without a termination clause (ROLLBACK AFTER, ROLLBACK IMMEDIATE, NO_WAIT) the ALTER DATABASE command will run until the command completes, or until if command is terminated.

The ROLLBACK AFTER command tells the SQL Server to cancel any pending transactions and rollback those transactions after N number of seconds.

ALTER DATABASE YourDatabase
...
WITH ROLLBACK AFTER 30

The ROLLBACK IMMEDIATE command tells the SQL Server that if it can’t complete the command right away, then the other pending transactions should be rolled back.

The NO_WAIT command has the opposite effect as ROLLBACK IMMEDIATE.  If the ALTER DATABASE transaction can’t be completed then that transaction is terminated.

ALTER DATABASE YourDatabase
...
WITH NO_WAIT

Hopefully this helps clear up some of the confusion.

Denny


Contact the Author | Contact DCAC

4 responses to “Understanding what the WITH ROLLBACK IMMEDIATE does”

  1. Jameslean says:

    The NO_WAIT command has the same effect as ROLLBACK IMMEDIATE.

    I don’t think this is correct. WITH ROLLBACK AFTER | IMMEDIATE specifies when any [B]other[/B] transactions in the database should be rolled back, eg when setting the db to single user mode.

    NO_WAIT specifies that if the ALTER DATABASE command cannot complete, ie other open transactions exist, then the ALTER command itself should rollback/fail.

  2. Jameslean says:

    NB, the first line in my above post is the quote that I don’t think is correct!

  3. mrdenny says:

    I’m not sure how I managed to get that so wrong. I’ve updated the blog post so that it’s correct.

  4. Fhhdjfhjdhfjhjdfh says:

    HI,

    when i run the command

    alter database northwind
    set multi_user with rollback immediate

    the northwind database shows ACCESS denied and tagged as SINGLE USER
    i donot understand why it so .can u pls explain .

Video

Globally Recognized Expertise

As Microsoft MVP’s and Partners as well as VMware experts, we are summoned by companies all over the world to fine-tune and problem-solve the most difficult architecture, infrastructure and network challenges.

And sometimes we’re asked to share what we did, at events like Microsoft’s PASS Summit 2015.

Awards & Certifications

Microsoft Partner    Microsoft MVP    Microsoft Certified Master    VMWare Partner    VMWare vExpert
   Best Full-Service Cloud Technology Consulting Company    Insights Sccess Award    Technology Headlines Award    Golden Bridge Gold Award    CIO Review Top 20 Azure Solutions Providers
Share via
Copy link