1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| USE sybsystemprocs
GO
IF OBJECT_ID('dbo.sp__Killusers') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.sp__Killusers
IF OBJECT_ID('dbo.sp__Killusers') IS NOT NULL
PRINT '<<< FAILED DROPPING PROCEDURE dbo.sp__Killusers >>>'
ELSE
PRINT '<<< DROPPED PROCEDURE dbo.sp__Killusers >>>'
END
GO
CREATE PROCEDURE dbo.sp__Killusers (@dbname varchar(30))
AS
BEGIN
SET NOCOUNT ON
DECLARE @user INT, @execstr VARCHAR(240), @username VARCHAR(30), @program_name VARCHAR(30), @workstr VARCHAR(30), @MySPID SMALLINT
SET @MySPID=@@spid******
IF "@dbname" <> "master"
BEGIN
IF EXISTS (SELECT spid FROM master..sysprocesses WHERE dbid = DB_ID(@dbname) AND (spid < 2 OR spid > 9) and spid != @MySPID)
BEGIN
WHILE ((SELECT count(spid) FROM master..sysprocesses WHERE dbid = DB_ID(@dbname) AND (spid < 2 OR spid > 9) and spid != @MySPID) > 0)
BEGIN
SELECT @user = p.spid,
@username = l.name,
@program_name = p.program_name,
@execstr = 'kill '+CONVERT(VARCHAR(3), p.spid),
@workstr = p.cmd
FROM master..sysprocesses p, master..syslogins l
WHERE dbid = DB_ID(@dbname)
AND p.suid = l.suid
AND p.spid != @MySPID
SELECT @user, @username, @program_name,@execstr, @workstr
WHILE (SELECT COUNT(spid) FROM master..sysprocesses WHERE spid = @user) > 0
BEGIN
EXEC (@execstr)
WAITFOR DELAY '00:00:05'
END
END
END
END
END
GO
EXEC sp_procxmode 'dbo.sp__Killusers', 'unchained'
GO
IF OBJECT_ID('dbo.sp__Killusers') IS NOT NULL
PRINT '<<< CREATED PROCEDURE dbo.sp__Killusers >>>'
ELSE
PRINT '<<< FAILED CREATING PROCEDURE dbo.sp__Killusers >>>'
GO |
Partager