Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Unsed Tables in Databse

 
   Database Help (Home) -> Programming RSS
Next:  Service Accounts  
Author Message
NAVIN.D

External


Since: Dec 29, 2008
Posts: 15



(Msg. 1) Posted: Wed Jan 28, 2009 9:39 pm
Post subject: Unsed Tables in Databse
Archived from groups: microsoft>public>sqlserver>programming (more info?)

DMV to identify the unsed tables and most used tables in database?

 >> Stay informed about: Unsed Tables in Databse 
Back to top
Login to vote
Patrik

External


Since: Jan 29, 2009
Posts: 1



(Msg. 2) Posted: Thu Jan 29, 2009 12:08 am
Post subject: Re: Unsed Tables in Databse [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

How do you define 'most used'?

///Patrik

On 29 Jan, 06:39, NAVIN.D wrote:
> DMV to identify the unsed tables and most used tables in database?

 >> Stay informed about: Unsed Tables in Databse 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 3) Posted: Thu Jan 29, 2009 4:25 am
Post subject: Re: Unsed Tables in Databse [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In SQL Server 2005 you can use the sys.dm_db_index_usage_stats data
management view
SELECT
last_user_update = MAX(last_user_update)
FROM
sys.dm_db_index_usage_stats
WHERE
[database_id] = DB_ID()




"NAVIN.D" wrote in message

> DMV to identify the unsed tables and most used tables in database?
 >> Stay informed about: Unsed Tables in Databse 
Back to top
Login to vote
Eric Russell

External


Since: Jun 16, 2008
Posts: 187



(Msg. 4) Posted: Thu Jan 29, 2009 9:40 am
Post subject: RE: Unsed Tables in Databse [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The following query returns each user table contained in a database and uses
two different methods to determine if it is "used". First, it determines if
the table name is contained within the text of any other object (stored proc,
view, trigger, or function) within the database. Also, it joins
[sys.dm_db_index_usage_stats] to determine if there are usage statisics for
that table. On a large systems with hundreds of tables and procedures, it may
take 1/2 an hour or more to complete.

Keep in mind that usage statistics are reset whenever the server is
rebooted, so you will need to fully regression test your application,
insuring that every module and function call is performed, prior to running
this query.

To be really thorough, when you have identified the those tables you suspect
are not used, regression test your application again with a SQL Profiler
trace running and filtering events on those specific objects.

select
(case when ObjectName is null and TotalUserAccess = 0 and
TotalSystemAccess = 0 then 'X' else '' end) as NotUsed,
*
from
(
select
TBL.name as TableName,
OBJ.name as ObjectName,
OBJ.type as ObjectType,
sum(isnull(user_seeks,0) + isnull(user_scans,0) +
isnull(user_lookups,0) + isnull(user_updates,0)) as TotalUserAccess,
sum(isnull(system_seeks,0) + isnull(system_scans,0) +
isnull(system_lookups,0) + isnull(system_updates,0)) as TotalSystemAccess
from sys.objects as TBL
-- Outer join, so it also lists non-referenced tables.
left join sys.syscomments as OBJTEXT
on OBJTEXT.text like '[^a-z,0-9,_]%' + TBL.name + '%[^a-z,0-9,_]'
left join sys.objects as OBJ
on OBJ.object_id = OBJTEXT.id and
OBJ.is_ms_shipped = 0 -- Exclude system objects
left join sys.dm_db_index_usage_stats as USAGESTATS
on USAGESTATS.object_id = TBL.object_id
where
TBL.type = 'U' and -- User Tables
TBL.is_ms_shipped = 0 -- Exclude system objects
group by
TBL.name,
OBJ.name,
OBJ.type
) as X
order by
(case when ObjectName is null and TotalUserAccess = 0 and
TotalSystemAccess = 0 then 'X' else '' end) desc,
TableName,
ObjectName


"NAVIN.D" wrote:

> DMV to identify the unsed tables and most used tables in database?
 >> Stay informed about: Unsed Tables in Databse 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
sharing a databse - I am very new to programing and serves ect and just learning. have just set up a business with a freind but we both work fro home. I have built an access database that we enter in ourcustomer details and any orders they place with us. As we both work....

Databse project group vs2005 missing - Hi, I am just attempting to create my first managed stored procedure. Started VS2005. went to File | New | Project Under C# There is no "Database" project node. I have visual studio 2005 and sql server 2005 standard edition installed on my d...

reconcile two tables - i trying to reconcile a log against files we recieve in from our clients. HeaderRecords contains the file Headers and DayRecLogs is the daytime log I need to show all files recieved that day and check tere is an enrty in the DayRecLogs for that file ...

Temp tables and SP - Hi, I have a StoredProcedure 'ProfitSP' in different databases and the ProfitSP is same in each database. If I execute ProfitSP as: <font color=purple> ; Exec DB1.dbo.ProfitSP @OrderStartDate, @OrderEndDate</font> it works fine! ...

Joining tables - I have two tables one table T1 only have one result per date table 2 T2 can range from 0 to 8 results per date, I want to pull back all of the results in T2 and sum the totals, in my example it will be summing "Stafftime" and "items&quo...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]