Tuesday, January 26, 2010

Find the database name from MDF also version, associate NDF’s and LDF’s list using T-SQL when we have just only primary MDF file in hand

--Is this MDF the primary file-group MDF file?

DBCC CHECKPRIMARYFILE ('D:\Program Files\Microsoft SQL Server\MSSQL10.SQL2K8\MSSQL\DATA\ac.mdf',0)

-- Get the list of related NDF, LDF file names and other detailed info

DBCC CHECKPRIMARYFILE ('D:\Program Files\Microsoft SQL Server\MSSQL10.SQL2K8\MSSQL\DATA\ac.mdf',1)

--Get the database name, version and collation this file is associated

DBCC CHECKPRIMARYFILE ('D:\Program Files\Microsoft SQL Server\MSSQL10.SQL2K8\MSSQL\DATA\ac.mdf',2)

-- Get a list of all files associated with the database.

DBCC CHECKPRIMARYFILE ('D:\Program Files\Microsoft SQL Server\MSSQL10.SQL2K8\MSSQL\DATA\ac.mdf',3)