netnerds.net

30Jan/073

T-SQL: Quickly Kick All Users Out of a SQL Server Database

There are a few ways to do this but here's one that I like. I believe it works in SQL Server 7, 2000 and 2005.

ALTER DATABASE myDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE myDatabaseName
GO

Go ahead and do what you need to do then set it back:

ALTER DATABASE myDatabaseName SET MULTI_USER
Posted by: Chrissy   Filed under: SQL Server Leave a comment
Comments (3) Trackbacks (0)
  1. Ah thanks! Worked well enough on sqlsrv2k.

    Saw that noone left any comment so I’ll just leave this here :)

    /K

  2. Thanks, this is exactly what I was looking for!

  3. This is a great and easy way ! Thanks a lot


Leave a comment


No trackbacks yet.