Click here to Skip to main content
16,020,622 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
How to find last 9 days activity for create and modified tables in SQL Server 2008.

Please help me, its urgent.
Posted
Updated 12-Jun-15 3:14am
v2
Comments
[no name] 12-Jun-15 9:13am    
No it's not urgent at all. Look through the databases log files.
Afzaal Ahmad Zeeshan 12-Jun-15 9:14am    
My virtual 5!

Hi,
SQL
SELECT * FROM sys.tables
     WHERE type='U' AND
     create_date > '2015-06-03 00:00:00.000' OR -- Provide your date
     modify_date > '2015-06-03 00:00:00.000' -- Provide your date

Thanks
Bimal
 
Share this answer
 
v2
Comments
ZurdoDev 12-Jun-15 9:27am    
This only gets created table, not modified ones, right?
Bimal pedini 12-Jun-15 9:40am    
yes
See this CP article: SQL Server: Search Stored Procedure Create/Modify Date or Text using T-SQL[^]

Prior to 2008 you could use
SQL
SELECT * FROM sys.tables
where create_date >= DATEADD(DAY, -9, dateadd(dd, datediff(dd, 0, GETDATE()), 0))
or modify_date >= DATEADD(DAY, -9, dateadd(dd, datediff(dd, 0, GETDATE()), 0))

Potentially you should now use
SQL
SELECT *
FROM INFORMATION_SCHEMA.TABLES  IS_T
INNER JOIN sysobjects  so ON IS_T.[TABLE_NAME] = so.[name]
where crdate >= DATEADD(DAY, -9, dateadd(dd, datediff(dd, 0, GETDATE()), 0))
or refdate >= DATEADD(DAY, -9, dateadd(dd, datediff(dd, 0, GETDATE()), 0))
Caveat - I'm not convinced that refdate is actually the last amended date - you will need to research further

Note the stuff I've done with the date - that is so that the comparison is based on the beginning of the day instead of the time of day that the query is run.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900