How to find unused Table and Recently executed query in Sql Server

Posted By  Mohammad Shahanshah Ansari On 22 Jun 2010 09:06:15
emailbookmarkadd commentsprint
No of Views:950
Bookmarked:0 times
Votes:0 times

How to find unused tables in SQL Server

Here's a query which can give you a clear idea about the unused tables in your database.

select 
t.name as 'table', 
sum(i.user_seeks + i.user_scans + i.user_lookups)as 'total accesses',sum(i.user_seeks) as 'seeks',sum(i.user_scans) as 'scans',sum(i.user_lookups) as 'lookups'from 
sys.dm_db_index_usage_stats i right outer join 
sys.tables t on (t.object_id = i.object_id)group by 
i.object_id, 
t.name
order by [total accesses] desc

How to Find Recently Executed Queries

Here is the query which we used to find out the recently executed queries along with the date and time at which they were executed.

SELECTDMExQryStats.last_execution_time AS [Executed At],DMExSQLTxt.text AS [Query]FROMsys.dm_exec_query_stats AS DMExQryStats
CROSS APPLY
sys.dm_exec_sql_text(DMExQryStats.sql_handle) AS DMExSQLTxt
ORDER BYDMExQryStats.last_execution_time DESC

Hope this will be useful to you also.

Sign Up to vote for this article
Other popular Tips/Tricks
    In this tips, I will explain how to ALTER or ADD two or more columns in to table by t-sql script.
    Published Date : 25/Mar/2011
    A very important feature of SQL Server 2008 is that we can enable CDC(Change Data capture) on database or table.We can track the database had CDC enabled by querying IS_CDC_ENABLED column
    Published Date : 17/Jan/2011
    A very important feature of SQL Server 2008 is that we can enable CDC(Change Data capture) on database or table.We can track the database had CDC enabled by querying IS_CDC_ENABLED column
    Published Date : 17/Jan/2011
    This is the third tips date related function in sql server. In this I going to show you how to use DATEDIFF() function in sql server. The DATEDIFF () is useful to get the specified date part between two dates
    Published Date : 16/Dec/2010
    The DATEADD function is a powerful built-in function sql server to add dates in different way and types. So I would like to explore in this tip how we can use the DATEADD function for different purpose.
    Published Date : 12/Dec/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top