CREATE PROCEDURE kill_database_users @arg_dbname sysname with recompileAS-- kills all the users in a particular database-- dlhatheway/3M, 11-Jun-2000declare @a_spid smallintdeclare @msg varchar(255)declare @a_dbid intselect @a_dbid = sdb.dbidfrom master..sysdatabases sdbwhere sdb.name = @arg_dbnamedeclare db_users insensitive cursor forselect sp.spidfrom master..sysprocesses spwhere sp.dbid = @a_dbidopen db_usersfetch next from db_users into @a_spidwhile @@fetch_status = 0 begin select @msg = 'kill '+convert(char(5),@a_spid) print @msg execute (@msg) fetch next from db_users into @a_spid endclose db_usersdeallocate db_usersGO