September 22, 2013 at 12:42 am
Dear All
I want to get last executed queries on a DB. Using dm_exec_query_plan , dm_exec_query_stats ,dm_exec_sql_text gives this information. But it shows null values for adhoc queries.
How to get DB id for adhoc queries?
Regards
September 22, 2013 at 5:09 am
Short of parsing the ad-hoc statement, figuring out which tables are there and linking them to a DB, you don't.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 22, 2013 at 5:53 am
Hi Gail
Sorry did not understand your reply.
Regards
September 22, 2013 at 7:29 am
There is no database ID for ad-hoc queries. You could try parsing the statement and figuring out which tables it uses and which DB those are in.
But then, what database should this be associated with?
USE master
SELECT * FROM db1.dbo.table1
Or this one
Use TempDB
SELECT *
Into NotTemp
FROM db1.dbo.table1 t1 inner join db2.dbo.table2 t2 on T1.SomeID = T2.SomeID
Edit: Or you might be able to parse it out of the query plan, if you're familiar with XML.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 22, 2013 at 9:45 pm
Hi Gail
Thanks. My requirement is to get the last few queries which were ran on a particular DB.
How to find it. Note : these quereies could be form application/procedures/SSMS
Regards
September 23, 2013 at 12:09 am
Try a server-side trace.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 26, 2013 at 5:13 am
Hi All
declare @id int
set @id = 100
select * from xxx where id =@id
if we run this through SSMS , is it considered as adhoc query?
Regrads
September 26, 2013 at 5:44 am
Yes.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 26, 2013 at 5:51 am
Hi
so any query which is not part of procedure or function is considered as adhoc?
Dose this means if we have written such queries in our front end applications these are also considerd as adoc?
Regards
September 26, 2013 at 7:46 am
Yes.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply