Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In the below query run to display dmlquery,datbasename,hostname...etc. So user table and master table queries are displayed but i want only user table queries like select * from sys.tables where type='U' and to find which table name in each query and also database.


SQL
SELECT distinct  dest.TEXT AS [Query],DB_NAME() as dbname,dess.host_name as 'Host Name',deqs.execution_count as count,deqs.creation_time as start_time,deqs.last_execution_time AS [last_execution_time]
		FROM sys.dm_exec_query_stats AS deqs
		CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest 
		cross apply sys.dm_exec_sessions dess
		cross apply sys.objects so
		where dest.text like 's%' and dess.session_id = @@spid and so.type='U'
		ORDER BY deqs.last_execution_time DESC 


thanks in advance
Posted
Updated 5-Oct-11 18:51pm
v3
Comments
Mehdi Gholam 5-Oct-11 8:55am    
Your question makes no sense, please edit it and supply more information.
K N R 6-Oct-11 0:52am    
Hi Mehdi,
thanks for your suggestion. i am providing some information regarding that query.
can you please help me...!

1 solution

Perhaps what you mean is that you want to retabulate what "SELECT * FROM sys.databases" returns without including the top four(4) tables of the results.

There are plenty of ways to do that but the easiest is to exclude the "owner_sid" field by tacking on a "WHERE [owner_id] != 0x01" to the above and that should give you the tablish output.

Something that always challenged me when I first signed on to T-SQL was the lack of an index in all this tabulation. Until I discovered "... IDENTITY(1,1) ..." in the help tome. 'Does it automatically during a CREATE TABLE pattern excersize and .. well look it up in help and see the light.

Happy index-adding!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900