Is there a way to check statistics for table access, by update, delete or select? Im trying to find obsolete unused tables for a database cleanup.
Thanks
Is there a way to check statistics for table access, by update, delete or select? Im trying to find obsolete unused tables for a database cleanup.
Thanks
Yes - you can create a trace, MSDN - Data Access Tracing in SQL Server 2005.
Alternatively, if you know what's accessing them (e.g. via stored procedures), you can leave trace information in them (adding rows to a table), then you can see what is actually being run. That's less foolproof - you're proving a negative, because you'll find it harder to catch the occasional hits.
One method we use is to just rename the tables, e.g. to 'zzz_OldName' and just leave them there for a while, periodically pruning that area of the schema.
As far as I know, there is no build in statistics for such data in Sql Server. Although you can use Sql Profiler to get usage data over a period of time.
You could check your DMV's (Dynamic Management Views). If your tables all have a primary key, there's a primary key index, and if that index is never being read, your table is not being used at all.
But mind you: these are dynamic management views - they get reset to 0 each time SQL Server starts up. You might want to look into either the SQL Server 2008 Performance DAta Collector or the SQL DMV Stats project for SQL Server 2005 to capture DMV data over an extended period of time before dropping a table :-)
Marc
Could also put a Trigger on the table to store TableName + GetDate() in a "WasFoundToBeUsedAfterAll" table
You probably want to UpSert any rows already there, and maybe only if existing Date is already 24 hours old, or more, rather than insert multiple rows - which will just become a maintenance problem all of its own!