all groups > sql server programming > june 2007 >
You're in the

sql server programming

group:

How to know the date of the last update of a table?


How to know the date of the last update of a table? newToSql
6/2/2007 6:41:49 PM
sql server programming:
Hi,
in sql 2k, one has to add a column to keep this info, But sql 2005 surely
keeps such info (date of the last update of a table) in its catalog.
but where?
Thanks

Re: How to know the date of the last update of a table? Kalen Delaney
6/2/2007 7:59:03 PM
This information is not stored automatically, even in SQL 2005.

--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com


[quoted text, click to view]

Re: How to know the date of the last update of a table? Tore
6/3/2007 12:00:00 AM
use getdate() in sql server to insert the date and time of the update into a
table column

update MyTableName
set MyColumnName = getdate()
where xxxxxxxxxxx

regards

Tore

Re: How to know the date of the last update of a table? Tony Rogerson
6/3/2007 12:00:00 AM
Hi,

In SQL Server 2005 you can use the sys.dm_db_index_usage_stats data
management view, look at the column last_user_update, you can also see when
the table was last accessed (last_user_seek and last_user_scan - do a MAX on
them).

select *
from sys.dm_db_index_usage_stats
where database_id = db_id( 'readpasttest' )

Note, this view is reset when SQL Server restarts so is only current since
SQL last started, but I suppose you could write some logic to capture the
value but it would be slightly out of date because you can't grab the event
when SQL Server is shutting down.

Tony.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]


[quoted text, click to view]
Re: How to know the date of the last update of a table? Hari Prasad
6/3/2007 12:00:00 AM
Hello,

In SQL 2005 also you may need to create a new column to know when the table
was last updated. In SQL 2005 Schema changes can be audited using
DDL triggers.

THanks
Hari

[quoted text, click to view]

Re: How to know the date of the last update of a table? newToSql
6/3/2007 1:22:47 PM
This is very helpful.Thank you so much.


[quoted text, click to view]

Re: How to know the date of the last update of a table? Kalen Delaney
6/4/2007 8:12:35 PM
I just had never used that view for this purpose, but it seems reasonable to
me. Give it a try.
This wouldn't be the first thing I'd learned from Tony.
:-)

--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com


[quoted text, click to view]

Re: How to know the date of the last update of a table? TheSQLGuru
6/4/2007 9:44:30 PM
Is Tony's suggestion to use sys.dm_db_index_usage_stats invalid?

--
TheSQLGuru
President
Indicium Resources, Inc.

[quoted text, click to view]

Re: How to know the date of the last update of a table? Tony Rogerson
6/5/2007 9:25:07 PM
Thanks Kalen, that is high praise.

But I don't think drinking large quantities of beer quickly counts ;)

Tony.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]


[quoted text, click to view]
Re: How to know the date of the last update of a table? Kalen Delaney
6/6/2007 5:55:17 AM
:-)
But that's something I'll never do as well as you.

--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com


[quoted text, click to view]

AddThis Social Bookmark Button