TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Kill users connected to SQL Server database
Midhun Tp
Aug 01
2016
Code
821
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
DECLARE
@DatabaseName nvarchar(50)
SET
@DatabaseName = N
'YOUR_DATABASE_NAME'
DECLARE
@SQL
varchar
(
max
)
SELECT
@SQL =
COALESCE
(@SQL,
''
) +
'Kill '
+
Convert
(
varchar
, SPId) +
';'
FROM
MASTER..SysProcesses
WHERE
DBId = DB_ID(@DatabaseName)
AND
SPId <> @@SPId
SELECT
@SQL
EXEC
(@SQL)
SQL