Creating new database with existing MDF(only MDF) file.

  • Dear All,

    I have downloaded MDF of my database from live server to local server.

    Now I want to create a database in loocal server pointing to this MDF file.

    How can I do it..?

    Thanks in advance.

    Santhu.

  • nairsanthu1977 (10/22/2008)


    Dear All,

    I have downloaded MDF of my database from live server to local server.

    Now I want to create a database in loocal server pointing to this MDF file.

    How can I do it..?

    Thanks in advance.

    Santhu.

    Attach that MDF

    USE [master]

    GO

    CREATE DATABASE [database_name] ON

    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\ .mdf' ),

    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.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'

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • Good Post.

    I forgot how to create a database from the .mdf and .ldf file but this reminded me.

    Thanks

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply