SQL Server Manager select and kill process query

Who is hogging the database process? This question can be hard to answer if you don’t have the right tools to view the Activity monitor. I got recently this problem.

SQL is an amazing language and MS SQL server can give you answers to about anything threw SQL queries. The query that answered my questions was this:

SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections,
loginame as LoginName
FROM sys.sysprocesses
WHERE dbid > 0
GROUP BY dbid, loginame

this query will show you a table over the databases, the number of active connections and the logins that are using them. After that you can run another query to kill all connections to a specific database like so:

DECLARE @DatabaseName nvarchar(50)
SET @DatabaseName = N'myDatabaseName'
--SET @DatabaseName = DB_NAME()

DECLARE @SQL varchar(max)
SET @SQL = ''

SELECT @SQL = @SQL + 'Kill ' + Convert(varchar, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

-- SELECT @SQL
EXEC(@SQL)
DEALLOCATE my_cursor

There are some other tricks at http://www.kodyaz.com/articles/kill-all-processes-of-a-database.aspx.

Print | posted on Wednesday, November 25, 2009 3:16 PM

Comments

Gravatar

# re: SQL Server Manager select and kill process query, Posted by pages de jeux on 4/10/2010 12:28 PM

SQL queries will differ greatly from one syntax to another, and thus, so too should the SQL injection. SQL server, then omitting the double dashes and ending single quote will get the desired results.

Gravatar

# re: SQL Server Manager select and kill process query, Posted by http://www.aicasinogioco.com/ on 5/25/2010 7:20 AM

The SQL is an amazing language and MS SQL server can give you answers to about anything threw SQL queries.
The Every Query are different from one Query to another Query....

Gravatar

# SQL Server Manager select and kill process query, Posted by DotNetShoutout on 10/5/2010 1:26 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Gravatar

# re: SQL Server Manager select and kill process query, Posted by columbia jackets on 10/15/2010 11:04 AM

After that you can run another query to kill all connections to a specific database like so:columbia shoes

Gravatar

# re: SQL Server Manager select and kill process query, Posted by snow boots for women on 10/17/2010 12:44 PM

this query will show you a table over the databases, the number of active connections and the logins that are using them.

snow boots | snow boots for women | cheap north face jackets | the north face outlet

Gravatar

# re: SQL Server Manager select and kill process query, Posted by Alvasin on 12/18/2011 6:31 PM

This is very nice information for word-press. I really liked that. music production

Comments

Title: *
Name: *
Email: (never displayed)
Website:
Comment: *  
Please add 4 and 1 and type the answer here: