March 11, 2015 at 5:55 am
I ran:
Update HumanResources.Department set Name = 'Doctor' where DepartmentID = 1
and then ran:
SELECT * FROM sys.tables order by modify_date desc
But modify_date didn't change to today's date!!!! am I missing something here?
March 11, 2015 at 5:58 am
Modified date tracks schema changes. Not data changes.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 11, 2015 at 6:02 am
Thanks for quick reply. How do I find which tables (data) were changed by date?
March 11, 2015 at 6:04 am
Short answer: You don't.
Custom auditing if you want accurate, persisted data. Or, you can look at sys.dm_db_index_usage_stats, however that only retains information until SQL Server or the database is restarted.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 11, 2015 at 6:06 am
you'd have to add something to the table ; either a new column of type datetime, plus a trigger to always populate it on update, or a column of type rowversion, so that you could tell the last row that was modified, but not WHEN it was modified.
if you need to actually track those things, ChangeTracking or Change Data Capture, or maybe SQL Audit are all possibilities.
Lowell
March 11, 2015 at 6:40 am
Thanks Lowell. What I am trying to find out on my Prod Database is which tables haven't been accessed, modified or updated for long time, so I can make a case to remove it. Is there best way to do this? Thanks.
March 11, 2015 at 6:48 am
Add one of the things that Lowell mentioned and monitor for a complete business cycle, be sure to include month and and year end in the time that you monitor for.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 11, 2015 at 12:46 pm
You can also get some idea of what's been used by querying sys.dm_db_index_usage_stats. That includes information for the last scan, last seek, last lookup, and last update for each index and heap.
Just keep in mind that in some situations those statistics will get cleared for a database or particular index (http://blogs.msdn.com/b/ialonso/archive/2012/10/08/faq-around-sys-dm-db-index-usage-stats.aspx has some good information). Also keep in mind that any indexes or heaps not accessed since the last restart will not have any rows here, so that's easy to exploit to see what hasn't been accessed.
That's a decent method for getting an idea of what's been used and how recently it was used, but for long term auditing or the like, you'd want to use one of the options Lowell mentioned.
Cheers!
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply