:::: MENU ::::

Get currently logged in users in your SQL Server Instance

  • Mar 05 / 2009
  • 2
dbDigger

Get currently logged in users in your SQL Server Instance

Analyzing current activities of users in your SQL Server is mandatory task for monitoring your SQL Server performance can be queried for this purpose with little alterations. For example to get current activities for database we can run script like

 
select hostname, program_name, loginame, cpu, physical_io,  
 memusage, login_time, last_batch, status  
 from master.dbo.sysprocesses  
 where dbid = db_id('AdventureWorks')  
 order by hostname  

Also a very efficient and informative system stored procedure is available to get same type of information. For example to get same information for our server instance

 
SP_WHO  
 GO  

Above stored procedure will provide valuable information for all databases. So you may choose either way according to your requirement. By using custom script there is choice to implement sorting and customizing the out put columns number.

  • Anonymous

    SQL Server 2005 users may also use

    select hostname, program_name, loginame, cpu, physical_io, memusage, login_time, last_batch, status
    from sys.sysprocesses
    where dbid = db_id(‘AdventureWorks’)
    order by hostname

  • Atif Shehzad

    To get users for all databases
    select db_name(dbid) as DB,hostname, program_name, loginame, cpu, physical_io, memusage, login_time, last_batch, status
    from sys.sysprocesses
    order by DB,hostname

Consult us to explore the Databases. Contact us