Complete a Server Assessment – Database File Information

Below you will find the code find information about the database files.  Simply select the text and copy to the Clipboard.

CREATE TABLE #DBInfo
( DatabaseName VARCHAR(128)
, DBFileName VARCHAR(128)
, FileName VARCHAR(500))

SET NOCOUNT ON
EXECUTE master.sys.sp_MSforeachdb ‘USE [?] INSERT INTO #DBInfo SELECT
DB_Name()
, name
, filename
FROM dbo.sysfiles a ‘

SELECT DatabaseName
, CONVERT(VARCHAR(50),DBFileName) AS ‘Name’
, LEFT(FileName , 3) AS ‘Drive’
, FileName
FROM #DBInfo
DROP TABLE #DBInfo

This code was written using the Microsoft SQL Server documentation.  If you find that this code was copied from else where, please let me know so I can give proper credit.