Skip to content

Instantly share code, notes, and snippets.

@marifrahman
Last active December 18, 2015 04:39
Show Gist options
  • Save marifrahman/5726800 to your computer and use it in GitHub Desktop.
Save marifrahman/5726800 to your computer and use it in GitHub Desktop.
Microsoft SQL Server Query to get the query being executed on a Database.
select S.program_name,DB_Name(S.dbid),min(S.last_batch), t.text as 'last_sql',S.loginame,count(*)
from sys.sysprocesses S
CROSS APPLY sys.dm_exec_sql_text (S.sql_handle) t
where S.dbid > 3
and DB_NAME (S.dbid) = 'MyDatabase'
group by S.program_name,S.dbid,t.text,S.loginame having count(*) > 6
order by count(*) desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment