Monday, April 18, 2011

T-SQL Admin 101: Retrieve list of databases

select * from sys.master_files

Returns database names (including log and ndf files), physical file locations, size, and more.

sp_helpdb

Stored procedure that returns database name, easy-to-read size, and recovery model (full/simple).

select * from sys.database_files

Returns database file names but limited to current database only.

select * from sys.databases

Returns database names, database_id, create_date, snapshot info, recovery info (full/simple), and many other options.  This is a good one.

select * from sys.master_files

More oriented toward the physical files, this returns physical filenames and many other options.  However, it does not return the database name (just the logical name of each file).

select * from sys.sysdatabases

Returns a list of databases and a few other options.  Not as thorough as sys.databases

select * from sys.sysfiles

Returns a list of file names for the current database

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.