Skip to content

Instantly share code, notes, and snippets.

@Cyberloki
Created September 22, 2013 21:44
Show Gist options
  • Save Cyberloki/6664170 to your computer and use it in GitHub Desktop.
Save Cyberloki/6664170 to your computer and use it in GitHub Desktop.
Query SP_Who Who is accessing particular database - shows loginname
DECLARE @coffee TABLE (
spid int
, ecid int
, [status] varchar(50)
, loginame varchar(255)
, hostname varchar(255)
, blk varchar(50)
, dbname varchar(255)
, cmd varchar(255)
, request_id int
)
INSERT INTO @coffee EXEC sp_who
SELECT * FROM @coffee where [dbname] = 'MyDB' order by loginame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment