Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Tables most and least used in SQL Server Expand / Collapse
Author
Message
Posted Tuesday, September 25, 2012 10:54 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, November 7, 2014 2:28 AM
Points: 268, Visits: 680
Hi,

I wanted to know this just to increased my information as i am a newbie. I found out this on internet but couldn't find out any satisfactory answer to this question. I would like to know the table which is the most and least used in the database.
Post #1364431
Posted Wednesday, September 26, 2012 12:56 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, November 15, 2012 9:14 PM
Points: 6, Visits: 73
Hope this helps you..

SELECT TableName, COUNT(*) [Dependency Count]
FROM (
Select Distinct
o.Name 'TableName',
op.Name 'DependentObject'
From SysObjects o
INNER Join SysDepends d ON d.DepId = o.Id
INNER Join SysObjects op on op.Id = d.Id
Where o.XType = 'U'
Group by o.Name, o.Id, op.Name
) x
GROUP BY TableName
ORDER BY 2 desc



Kivan G
Post #1364460
Posted Wednesday, September 26, 2012 1:03 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 12:18 PM
Points: 5,438, Visits: 7,606
Do not trust sysdepends, it lies like a rug.

There is no easy method to be sure of how often a table is used, particularly for select statements. You'd start with tracing proc calls and ad hoc queries and drill down on their counts, which will eventually lead you to the tables. You would then extrapolate from there.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1364462
Posted Wednesday, September 26, 2012 1:24 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:03 AM
Points: 40,385, Visits: 36,829
On 2008, use sys.dm_sql_referenced_entities and sys.dm_sql_referencing_entities. They're a hell of a lot more reliable that sysdepends.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1364475
Posted Wednesday, September 26, 2012 4:04 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:26 AM
Points: 14,000, Visits: 28,380
It does depend on how you defined "used". You could also take a look at the index usage statistics to see how often a clustered index (which is a table) or a heap (table w/o a clustered index) is accessed. This is a really simple example:

SELECT	OBJECT_NAME(object_id, database_id) AS ObjectName,
ddius.user_lookups,
ddius.user_scans,
ddius.user_seeks,
ddius.user_updates
FROM sys.dm_db_index_usage_stats AS ddius
WHERE OBJECTPROPERTY(ddius.object_id, 'IsUserTable') = 1;



----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1364544
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse