Sql-server – Opening .mdf files

sql serversql-server-2005

Apologies for the newbie question – I've got a .mdf file, and I've no idea how to run queries against it. I've downloaded and installed SQL Server Express 2005, but don't know when to start. I know that I'm not meant to open the file directly, but don't know what I am meant to do.

Could someone post a step by step of how to get to the point of running SQL queries against the file?

Best Answer

After you have installed SQL Server Express Edition/SQL Management Studio Express and tried the answers mentioned by other posters and still have problems attaching due to no log file the following command may be of use to you:

sp_attach_single_file_db @dbname= 'ENTER_DB_NAME', @physname= 'SOMEDRIVE:\SOME\LOCATION\TO\THE\DATABASEFILE.mdf'

This will attach the database and create a blank logfile for it.

Hope this helps you!