1

I have an .mdf file, and I'd like to create a database from it on my computer. But I'd like to create it without attaching it to the .mdf file.

Is this possible?

2
  • 2
    You cannot "create a database from an .mdf file" - it IS the database. It's a SQL Server file, and to use it, you need to attach it to a running SQL Server instance. No way around that.... Commented Jan 29, 2011 at 22:19
  • 1
    Why don't you want to attach it? Commented Jan 29, 2011 at 22:23

2 Answers 2

2

If you are trying to use the MDF as a template, for creating another database, you could simply copy it to a new file and then attach to the copy - but perhaps if you explained what you are trying to accomplish, and why you can't attach to the MDF, you might get better help.

Sign up to request clarification or add additional context in comments.

Comments

2

You can create database from your mdf file,please see my example below

USE [master]
GO
CREATE DATABASE [DatabaseName] ON 
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\...mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\...ldf' )
FOR ATTACH ;
GO

in case if you dont have the /ldf file : use this

EXEC sp_attach_single_file_db @dbname = 'pubs',
@physname = 'C:\MSSQL\Data\pubs.mdf'

1 Comment

If you are going to copy something verbatim from technet, please give credit to the source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.