Home All Groups Group Topic Archive Search About

Create MDF from Database

Author
7 Jul 2006 8:59 PM
porko
How does one create an .MDF file from the contents of an existing SQL Server
database?

I've tried backing up the SQL database, then restoring it to an attached
..MDF database, but this doesn't work if the other database is still being
managed by SQL Server, due to a name conflict.

There must be some easy way to do this.

Author
7 Jul 2006 9:44 PM
Kalen Delaney
If you have a database, you already have an .MDF file. That is where your
database is actually stored on disk.

What are you trying to do?

--
HTH
Kalen Delaney, SQL Server MVP


Show quote
"porko" <po***@discussions.microsoft.com> wrote in message
news:60DBF209-EC39-4DE4-8590-B167A85ED839@microsoft.com...
> How does one create an .MDF file from the contents of an existing SQL
> Server
> database?
>
> I've tried backing up the SQL database, then restoring it to an attached
> .MDF database, but this doesn't work if the other database is still being
> managed by SQL Server, due to a name conflict.
>
> There must be some easy way to do this.
Author
7 Jul 2006 10:44 PM
Erland Sommarskog
porko (po***@discussions.microsoft.com) writes:
> How does one create an .MDF file from the contents of an existing SQL
> Server database?
>
> I've tried backing up the SQL database, then restoring it to an attached
> .MDF database, but this doesn't work if the other database is still being
> managed by SQL Server, due to a name conflict.
>
> There must be some easy way to do this.

You can restore a backup and create new database at the same time.
Say that you have a database porko, and you want to create a copy,
porko_copy. First you backup porko to, say, C:\temp\porko.bak.

Next you can restore porko_copy as

  RESTORE DATABASE porko_copy FROM DISK = 'C:\temp\porko.bak'
  WITH MOVE 'porko_Data' TO
          'C:\program files\Microsoft SQL Server\MSSQL\Data\porko_copy.mdf',
       MOVE 'porko_Log' TO
          'C:\program files\Microsoft SQL Server\MSSQL\Data\porko_copy.ldf',
       REPLACE

porko_Data and porko_Log rae the logical file names for the database
files.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button