按创建顺序列出一台 SQL Server 上的所有数据库 [英] List all the databases on one SQL Server in the order they were created

查看:33
本文介绍了按创建顺序列出一台 SQL Server 上的所有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个 SQL Server (2005) 实例上,我可能拥有超过 100 个数据库.我想按照创建日期的顺序列出它们,或者更好的是按照对任何表的最新修改日期的顺序列出.

I have probably in excess of 100 databases on this one SQL Server (2005) instance. I'd like to list them in order of their create dates, or even better, in the order of the date of the latest modification to any table.

是否有我可以编写的 SELECT 查询,同样重要的是,我要从什么上下文编写它以及我需要什么权限来执行它?

Is there a SELECT query I can write, and just as importantly, from what context do I write it and with what permissions do I need to execute it?

推荐答案

您可以针对 sys.databases 目录视图轻松编写此查询

You can easily write this query against the sys.databases catalog view

SELECT * FROM sys.databases
ORDER BY create_date 

但不幸的是,我所知道的最后修改日期"没有等价物......

but unfortunately, there's no equivalent for the "last modification date" that I'm aware of ...

这应该适用于该服务器上的任何数据库 - 无论您在哪个数据库中,那些 sys 目录视图都应该可以从任何地方访问.

This should work from any database on that server - doesn't matter which database you're in, those sys catalog views should be accessible from anywhere.

这篇关于按创建顺序列出一台 SQL Server 上的所有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆