且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在sql server 2008中查找最近9天创建和修改的表

更新时间:2023-12-01 14:43:28



  SELECT  *  FROM  sys.tables 
WHERE type = ' U' AND
create_date> ' 2015-06-03 00:00:00.000' - 提供您的日期
modify_date> ' 2015-06-03 00:00:00.000' - 提供您的日期



谢谢

Bimal


请参阅此CP文章: SQL Server:搜索存储过程使用T-SQL创建/修改日期或文本 [ ^ ]



2008年之前你可以使用
  SELECT  *  FROM  sys.tables 
其中 create_date> = DATEADD(DAY,-9,dateadd(dd,datediff(dd, 0 ,GETDATE()) , 0 ))
mo dify_date> = DATEADD(DAY,-9,dateadd(dd,datediff(dd, 0 ,GETDATE()), 0 ))



您现在可能应该使用

  SELECT  * 
FROM INFORMATION_SCHEMA.TABLES IS_T
INNER JOIN sysobjects so ON IS_T。[TABLE_NAME] = so。[name]
其中 crdate> = DATEADD(DAY,-9,dateadd(dd,datediff(dd, 0 ,GETDATE()), 0 ))
refdate> = DATEADD(DAY,-9,dateadd(dd,datediff(dd, 0 ,GETDATE()), 0 ))

警告 - 我是不相信 refdate 实际上是最后一次修改日期 - 你需要进一步研究



注意我用日期做的事情 - 这样比较是基于当天的开始而不是查询运行的时间。


How to find last 9 days activity for create and modified tables in SQL Server 2008.

Please help me, its urgent.

Hi,
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


See this CP article: SQL Server: Search Stored Procedure Create/Modify Date or Text using T-SQL[^]

Prior to 2008 you could use
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

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.