I have a Microsoft SQL Server instance on my server with more than 100 databases and users. Sometimes, the SQL Server process use 100% of server CPU and I want to know which query/user/database is causing this and using so much resources.
For MySQL, I use the mysqladmin pr
command to see which users are currently connected. Also, the slow query log shows the queries that take more than X seconds to be completed.
I would like to know if there are similar commands for SQL Server.
Best Answer
There's a ton of dynamic management views (DMVs) you can use to get the data, but the easiest way is to use Adam Machanic's sp_WhoIsActive stored proc. Here's a video on how to use it:
http://www.brentozar.com/archive/2010/09/sql-server-dba-scripts-how-to-find-slow-sql-server-queries/
And you can download it from here:
http://whoisactive.com/
The output includes columns for the database name, CPU cycles used, query duration, and more.