Wednesday, March 7, 2012

ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK AFTER n

Let's assume I issue the following command: ALTER DATABASE [dbname] SET
SINGLE_USER WITH ROLLBACK AFTER 60.
Can someone tell me if the follow assumptions are correct:
1) SQL Server will wait 60 seconds for all open transactions to commit or
rollback before putting the database in single user mode.
2) Any transactions not committed or rolled back within 60 seconds will
automatically be rolled back after 60 seconds.
3) Any transaction started after the above statement is issued but is not
committed or rolled back within the 60 seconds gets rolled back.
Thanks - Amos.On Tue, 26 Sep 2006 11:27:52 -0400, Amos Soma wrote:

>Let's assume I issue the following command: ALTER DATABASE [dbname] SET
>SINGLE_USER WITH ROLLBACK AFTER 60.
>Can someone tell me if the follow assumptions are correct:
>1) SQL Server will wait 60 seconds for all open transactions to commit or
>rollback before putting the database in single user mode.
It will wait for _AT MOST_ 60 seconds for open connections to close. If
there are no open connections, the database is put in single user mode
immediately. If all other connections disconnect after 20 seconds, the
DB will be single user after 20 seconds.

>2) Any transactions not committed or rolled back within 60 seconds will
>automatically be rolled back after 60 seconds.
Yes. And all connections get disconnected.

>3) Any transaction started after the above statement is issued but is not
>committed or rolled back within the 60 seconds gets rolled back.
Only from connections that are already connected to the database
[dbname]. New connections are not accepted - you'll get this error:
Msg 952, Level 16, State 1, Line 1
Database 'dbname' is in transition. Try the statement later.
Hugo Kornelis, SQL Server MVP|||Hugo,
That was very helpful - thank you.
"Hugo Kornelis" <hugo@.perFact.REMOVETHIS.info.INVALID> wrote in message
news:hu6jh2ls21ckm5hbv7i8et0a6irud11lcv@.
4ax.com...
> On Tue, 26 Sep 2006 11:27:52 -0400, Amos Soma wrote:
>
> It will wait for _AT MOST_ 60 seconds for open connections to close. If
> there are no open connections, the database is put in single user mode
> immediately. If all other connections disconnect after 20 seconds, the
> DB will be single user after 20 seconds.
>
> Yes. And all connections get disconnected.
>
> Only from connections that are already connected to the database
> [dbname]. New connections are not accepted - you'll get this error:
> Msg 952, Level 16, State 1, Line 1
> Database 'dbname' is in transition. Try the statement later.
> --
> Hugo Kornelis, SQL Server MVP

No comments:

Post a Comment