13

I was hoping to be able to open .mdf file. I am using WebMatrix, I can view the queries there. I can read the schema too. But how can I read the file without using WebMatrix. Its SQL Server file not the Comptact edition.

I have searched for web help (Through windows). But all in vain. I will prefer any link or any method to read the basic queries.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103

2 Answers2

14

.sdf is, in fact, a Compact Database file (unless you've changed the extension which would be problematic). SQL Server would be .mdf.

SQL Server (.mdf)

You can attach the database to your local SQLEXPRESS instance and view it. An example of attaching it can be found on msdn: How to: attach a Database File to SQL Server Express. Essentially you're calling:

USE [master]
GO

CREATE DATABASE [database_name] ON 
    ( FILENAME = N'C:\Path\To\<database name>.mdf' ),
    ( FILENAME = N'C:\Path\To\<database name>.ldf' )
    FOR ATTACH ;
GO

SQL Compact Edition (.sdf)

The best tool I've found to open them is CompactView.

screenshot

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • Sorry It was my bad. I have just edited the file name! Actually I am having two folders one is the folder for App_Data (The one that is in the documents) and the other in C:\. So it just slipped off my mind. Sorry – Afzaal Ahmad Zeeshan Aug 19 '13 at 00:06
  • 1
    @AfzaalAhmadZeeshan: No worried; Updated the answer for accommodate for `.mdf`. best thing to do is just attach it to your local SQLEXPRESS. (A walk-through can be found [here](http://www.youtube.com/watch?v=rhIr9Qf-oHw)) – Brad Christie Aug 19 '13 at 00:12
  • Sorry youtube is blocked here! :( Will try to Google it. Anyways thanks :) – Afzaal Ahmad Zeeshan Aug 19 '13 at 00:16
1

SysTools SQL MDF Viewer can be used to view the table contents. I tried with the free trial version.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
hailinzeng
  • 966
  • 9
  • 24