Monday, June 11, 2012

DBCC CheckPrimaryFile -- Attach Detach MDF, LDF

I have given a MDF file to you and asked you find out name of the database, Is it possible?
Yes It is possible using a command DBCC CheckPrimaryFile

DBCC CheckPrimaryFile ('Path of Mdf File', 2) -- Displays name of the database, database version, collation

DBCC CheckPrimaryFiles -- This command is very useful while you are attaching database of one server to other server.

DBCC checkprimaryfile('C:\MSSQL\DATA\TESTDB.mdf',0) -- Displays whether the file is MDF or not

DBCC checkprimaryfile('C:\MSSQL\DATA\TESTDB.mdf',2) -- Displays name of the database, version of database and collation .

DBCC checkprimaryfile('C:\MSSQL\DATA\TESTDB.mdf',1) -- Displays complete information about the database files, similar to database..sysfiles

DBCC checkprimaryfile('C:\MSSQL\DATA\TESTDB.mdf',3) -- Displays logical and physical information of the database.

No comments: