Kill all USer Sessions before starting to restore a Database

  • Comments posted to this topic are about the item Kill all USer Sessions before starting to restore a Database

    Thanks.

  • USE [master]

    GO

    ALTER DATABASE [MyDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

    RESTORE DATABASE MyDatabase FROM ...

  • Is it worth mentioning that sysprocesses is a deprecated table?

    SQL DBA
    Every day is a school day, and don't trust anyone who tells you any different.
    http://sqlblogness.blogspot.co.uk

  • Thanks for the useful script. We do restores into testing environments quite often and run into the problem of having to find out who is in that environment and have them exit.

  • Unfortunately, you have to go back before SQL 2005 for this to be a "useful" script, since ALTER DATABASE provided a vastly better way to do this.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • This will not kill the sessions that are running queries from another database on the same instance.

  • Why not ?

    USE master

    go

    ALTER DATABASE <your database name> SET OFFLINE WITH ROLLBACK IMMEDIATE

    go

    ALTER DATABASE <your database name> SET ONLINE

    go

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply