How do I use sp_who2 and the sysprocess table

I need to monitor the jobs that are running in a particular database

when I use sp_who2, I only see the job or sql's that I am running locally from MS SQL Server studio
Also when I use select * from sysprocess, it gives me invalid object name.

How do I use these stored procedure and comand
LVL 1
countrymeisterAsked:
Who is Participating?
 
brejkConnect With a Mentor Commented:
Try the following:

select db_name(dbid) as db, *
from master.dbo.sysprocesses
order by db

This will return all sessions and they will be sorted by database name (additional first column named db).
0
 
brejkCommented:
select * from master.dbo.sysprocesses
0
 
brejkCommented:
More precisely:

select * from master.dbo.sysprocesses where dbid = db_id('YourDatabaseName')
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
brejkCommented:
But in SQL Server 2005 you may also query like this:

select *
from sys.dm_exec_sessions s
inner join sys.dm_exec_connections c
on s.session_id = c.session_id
cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) t
where t.dbid = db_id(N'YourDatabaseName')
0
 
brejkCommented:
Sorry, my last query will not succeed. It will return any records only dbid for stored procedures, not for ad-hoc queries.
0
 
countrymeisterAuthor Commented:
hi ! brejk

I get 0 rows affected when I run the foll query

select * from master.dbo.sysprocesses where dbid = db_id('exporttrades')
Pretty sure there are jobs running in the database
also tried sp_who2 and it shows nothing, Is this some privileges that I need on the database to view this information
0
 
countrymeisterAuthor Commented:
tried it, just shows me my sql run information
0
 
brejkCommented:
@countrymeister: Could you specify your needs? What do you want to display? And what do you mean writing "jobs"? SQL Agent jobs?
0
 
countrymeisterAuthor Commented:
brejk

I need to see all the jobs that are running on a database, when i do run sp_who2 i only see my jobs running, not someone else's job which I do know are running
0
 
countrymeisterAuthor Commented:
brejk, the issue was my userid was not set with the right permissions, I can see the jobs fine now
0
 
RavinderPanchalCommented:
Hi all , is there any option aor query through which i find that the which DML query execute by whom at what time
0
 
brejkCommented:
Hi RavinderPanchal,

Run Server Trace to capture query activity. Also you can capture queries run at the moment with sys.dm_exec_requests combined with sys.dm_exec_sql_text.
0
All Courses

From novice to tech pro — start learning today.