Drop Database with Active Connections

  • This command will take your database offline and kill all sessions

    USE master

    go

    ALTER DATABASE <your database name>

    SET OFFLINE

    WITH ROLLBACK IMMEDIATE

    to bring the database back online

    USE master

    go

    ALTER DATABASE <your database name>

    SET ONLINE

    And thats it

     

    Jolley

  • Another method is

    USE master

    go

    DECLARE @spid int

    SELECT @spid = min(spid) from master.dbo.sysprocesses where dbid = db_id()

    WHILE @spid IS NOT NULL

    BEGIN

    EXECUTE ('KILL ' + @spid)

    SELECT @spid = min(spid) from master.dbo.sysprocesses where dbid = db_id() AND spid > @spid

    END


    Julian Kuiters
    juliankuiters.id.au

Viewing 2 posts - 1 through 3 (of 3 total)

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