Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Kill process.

Author  Topic 

rj_khatri
Starting Member

13 Posts

Posted - 2003-07-19 : 01:58:39
Dear Friends,
Hi!!

Is there any command to kill all the running user processes in one run
or do i need to get the process id one by one and then kill.

Thanks

Rajesh Khatri

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-07-19 : 03:58:54
quote:

Dear Friends,
Hi!!

Is there any command to kill all the running user processes in one run
or do i need to get the process id one by one and then kill.

Thanks

Rajesh Khatri


U can use KILL to kill all the runnung processess,this can be done one by one only ,u can write a stored procedure to automate it.

The Judgement of the Judge is as good as the Judge.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-07-21 : 10:33:13
ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE



Brett

8-)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-07-21 : 12:34:42
declare @Doomeduserid varchar(3)

While exists(select * from master..sysprocesses where db_name(dbid) = 'DBNameGoesHere' and spid <> @@spid)

Begin

SELECT @Doomeduserid = convert (varchar(3),(select max(spid)
from sysprocesses where db_name(dbid) = 'DBNameGoesHere' and spid <> @@spid))

exec ("kill " +@Doomeduserid )

END



The above worked for SQL 7.0. I have not used it for 2000, but it will probably work. Why do you want to kill all of the processes anyway though? If it is because you are going to restore the database, then just run the code that Brett posted. But if you just want everybody out and not change the database state, then try the above code.

Tara
Go to Top of Page
   

- Advertisement -