Home All Groups Group Topic Archive Search About

How to lock entire database?

Author
12 May 2005 3:22 PM
Piotr Strycharz
Hi,

Is there a way to lock entire database? What I am supposed to do is kind of
replication:
- a number tables exist in database, these tables should be updated
- so, temporary tables are created and filled with data
- these temporary tables are renamed to final name (using sp_rename)

This is something like 'restore database', but should not terminate database
connections.

During renaming no process should access tables. How to ensure if no
transaction is running on destination tables? I can check sp_lock output for
exclusive locked tables, wait for transactions to finish, than run my
sp_rename script.
However the final question is: how to prevent NEW transactions? Or: how to
queue transactions to run AFTER sp_rename

Regards.

Piotr.

Author
12 May 2005 3:36 PM
Alejandro Mesa
Using "ALTER DATABASE" and setting it to SINGLE_USER state.


AMB

Show quote
"Piotr Strycharz" wrote:

> Hi,
>
> Is there a way to lock entire database? What I am supposed to do is kind of
> replication:
> - a number tables exist in database, these tables should be updated
> - so, temporary tables are created and filled with data
> - these temporary tables are renamed to final name (using sp_rename)
>
> This is something like 'restore database', but should not terminate database
> connections.
>
> During renaming no process should access tables. How to ensure if no
> transaction is running on destination tables? I can check sp_lock output for
> exclusive locked tables, wait for transactions to finish, than run my
> sp_rename script.
> However the final question is: how to prevent NEW transactions? Or: how to
> queue transactions to run AFTER sp_rename
>
> Regards.
>
> Piotr.
>
>
Author
16 May 2005 7:34 AM
Piotr Strycharz
Użytkownik "Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> said:

> Using "ALTER DATABASE" and setting it to SINGLE_USER state.

This command, however, won't allow change when connections exists (or are
made) to database.

Regards.
Author
16 May 2005 8:24 AM
Tibor Karaszi
You can use the ROLLBACK option to force out existing users.

Show quote
"Piotr Strycharz" <Piotr.Strycharz@antispam-account.com> wrote in message
news:d69ip4$m0$1@nemesis.news.tpi.pl...
>
> Uzytkownik "Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> said:
>
>> Using "ALTER DATABASE" and setting it to SINGLE_USER state.
>
> This command, however, won't allow change when connections exists (or are
> made) to database.
>
> Regards.
>
>

AddThis Social Bookmark Button