Understanding what the WITH ROLLBACK IMMEDIATE does

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.

SQL:
  1. ALTER DATABASE YourDatabase
  2. 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.

SQL:
  1. ALTER DATABASE YourDatabase
  2. WITH NO_WAIT

 

Hopefully this helps clear up some of the confusion.

Denny

 

Comment on this Post


You must be logged-in to post a comment. Log-in/Register

Jameslean  |   Sep 24 2009   4:05PM GMT

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 other 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.

 


 


Jameslean  |   Sep 24 2009   4:06PM GMT

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

 


 


mrdenny  |   Sep 24 2009   6:26PM GMT

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

 


 


Fhhdjfhjdhfjhjdfh  |   May 21 2010   10:30AM GMT

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 .

转载于:https://www.cnblogs.com/flysun0311/archive/2011/11/24/2261692.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值