SQL Server 数据库上次更新日期时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29535074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:29:47  来源:igfitidea点击:

SQL Server database last updated date time

sqlsql-serverdatabasesql-scripts

提问by Nagendra Baliga

Is there any sql script to find out when the database in SQL server is last updated?

是否有任何 sql 脚本可以找出 SQL Server 中的数据库上次更新时间?

I want to know the last updated date time for the changes done on meta data of the database rather than actual data inside the table. Particularly when:

我想知道对数据库元数据所做更改的最后更新日期时间,而不是表中的实际数据。特别是当:

  • Any new table is created/dropped from Database.
  • Any new column is added/removed from table in the Database.
  • Any new views/Stored Procedures/Functions are added/altered inside the Database.
  • 从数据库中创建/删除任何新表。
  • 在数据库的表中添加/删除任何新列。
  • 任何新的视图/存储过程/函数都会在数据库中添加/更改。

回答by Daniel Stackenland

Look in sys.objects should be enough, try this query

查看 sys.objects 应该就足够了,试试这个查询

 select * from sys.objects
order by modify_date desc

回答by Stanislovas Kala?nikovas

This will return last modified date time + name of updated item + description what was updated (table, stored procedure, etc)

这将返回上次修改日期时间 + 更新项目的名称 + 更新内容的描述(表、存储过程等)

SELECT TOP 1 name, modify_date, type_desc
FROM  sys.objects
ORDER BY modify_date DESC

回答by BDEZ

SELECT 
   [rs].[destination_database_name], 
   [rs].[restore_date], 
   [bs].[backup_start_date], 
   [bs].[backup_finish_date], 
   [bs].[database_name] as [source_database_name], 
   [bmf].[physical_device_name] as [backup_file_used_for_restore]
FROM msdb..restorehistory rs
INNER JOIN msdb..backupset bs ON [rs].[backup_set_id] = [bs].[backup_set_id]
INNER JOIN msdb..backupmediafamily bmf ON [bs].[media_set_id] = [bmf].[media_set_id]