I have never worked on SQL Server 2000 and I got a requirement to check capture the following information to one particular database.
DBName CurrentDate SPID BatchDuration ApplicationName HostName LoginName SQLQuery
I tried the query below but it in first place did not return any information or does not meet the requirement as it does not capture the ApplicationName and SQL Text.
SELECT
DB_NAME(dbid) as dbName
, CURRENT_TIMESTAMP as CurrentDate
, P.spid
, right(convert(varchar,
dateadd(ms, datediff(ms, P.last_batch, getdate()), '2000-01-01'),
121), 12) as 'batch_duration'
, P.program_name
, P.hostname
, P.loginame
, P.cmd
from master.dbo.sysprocesses P
where P.spid > 50
and P.status not in ('background', 'sleeping')
and P.cmd not in ('AWAITING COMMAND'
,'MIRROR HANDLER'
,'LAZY WRITER'
,'CHECKPOINT SLEEP'
,'RA MANAGER')
and DB_NAME(dbid) ='master'
order by batch_duration desc
Also when I try to setup this script via SQL Agent it only allows to run it every one minutes interval. Is there any other better way to run it like every 5 seconds? or maybe I should be using another method instead e.g. capturing the logins with required information via trigger instead?
Any input will be appreciated.