I know that this is a strange requirement but I need to find out database user name(not the login name) from sys.sysprocesses for all the currently running processes. For e.g. select spid,dbid, uid from sysprocesses where uid corresponds to database user in that particular database. So what I want is one more column which can get me database user name from uid. Please let me know if this is possible with just a simple select query.
Sql-server – Find database user name from sysprocesses
scriptingsql server
Related Question
- Sql-server – Do user database settings affect maintenance job times for system databases
- SQL Server – Finding Replacement for sys.sysprocesses
- Sql-server – the SQL Azure equivalent of the server “public” role
- SQL Server – Logon Auditing and Reporting Data from DB Table
- Sql-server – SQL Server instance level action tracking
- SQL Server – Why and How to Use User Without Login
Best Answer
Logins (on the server) do not automatically correspond to users (in the database). For instance, "sa" does not have its own user in the database, but uses "dbo". This might get you started.
Note:
sysprocesses
,sysusers
, etc are deprecated and will probably stop working in a future version of SQL Server.I go into a bit more detail on SQL Server security in my blog post.