I'm calling stored proc through a service. I wanted my stored proc to be running on a database. I've two questions
- Is sys.dm_* tables specific to a database or it is general one?
select * FROM sys.dm_exec_requests
Does above query return requests of all the databases or the current database where the query is being executed?
- If sys.dm_* specific to a database is there any way to specify the database through stored procedure. I'm aware that we cannot use
use. andselect * FROM [dbname].sys.dm_exec_requestsisn't working it seems. It returns the result for the current DB it seems. I may be wrong here.
It looks like the
dm_*tables are global to the system. The statementselect * from [dbname].sys.dm_exec_requestsreturns data for all databases on the server. If the table contains database specific data, then it will include adatabase_idfield.If you want to limit the data your stored procedure returns to just one database, then you have to qualify by
database_id. Both of the following statements work in stored procedures: