Activities on SQL server
This SQL script creates a temporary table named @Table and populates it with the results of the system stored procedure sp_who2, which returns information about active connections to a SQL Server instance. The SELECT statement then retrieves all rows from @Table where the DBName column matches any value, effectively returning information about all active connections regardless of the database they are connected to.
info
Before running the script please fill out the variables
{DATABASE NAME}
If you leave the %
you will find all activities in any database containing the {DATABASE NAME}
DECLARE @Table TABLE(
SPID INT,
Status VARCHAR(MAX),
LOGIN VARCHAR(MAX),
HostName VARCHAR(MAX),
BlkBy VARCHAR(MAX),
DBName VARCHAR(MAX),
Command VARCHAR(MAX),
CPUTime INT,
DiskIO INT,
LastBatch VARCHAR(MAX),
ProgramName VARCHAR(MAX),
SPID_1 INT,
REQUESTID INT
)
INSERT INTO @Table EXEC sp_who2
SELECT *
FROM @Table
WHERE DBName LIKE '%{DATABASE NAME}%'