List all the databases on one SQL Server in the order they were created

前端 未结 3 1273
天涯浪人
天涯浪人 2021-02-07 08:53

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 dat

3条回答
  •  醉梦人生
    2021-02-07 09:20

    create table #db_name (db_name nvarchar(128), last_change datetime);
    exec sp_MSForEachDB 'Use ?; insert into #db_name (db_name, last_change) select ''?'', max(modify_date) from sys.tables'
    select * from #db_name order by last_change desc
    

    this is not exactly one select but at least you got what you want. I'm db_owner on one of our databases and probably nothing impressive server-wide so it's not very demanding.

提交回复
热议问题