Knowing the SPID of the current session we are using.
select @@SPID
To know the database name from the dbid
select DB_Name (DBID) and viceversa, select db_ID (DBname)
We can get the query being executed on any session using the below query.
DECLARE @Handle varbinary(64);
SELECT @Handle = sql_handle
FROM sys.sysprocesses
WHERE spid = 62;
SELECT text FROM ::fn_get_sql(@Handle)
select @@SPID
To know the database name from the dbid
select DB_Name (DBID) and viceversa, select db_ID (DBname)
We can get the query being executed on any session using the below query.
DECLARE @Handle varbinary(64);
SELECT @Handle = sql_handle
FROM sys.sysprocesses
WHERE spid = 62;
SELECT text FROM ::fn_get_sql(@Handle)
Thanks for sharing this query. I found good information from http://www.lepide.com/sql-server-audit/ that enables the user to audit all SQL servers database within the entire network using a centralized platform and allows to audit specific user activities and operations as per your requirement.
ReplyDelete