开发者

Create database from .mdf file without attaching?

开发者 https://www.devze.com 2023-02-07 16:59 出处:网络
I have an .mdf file, and I\'d like to create a database from it on my computer. But I\'d like to create i开发者_如何学编程t without attaching it to the .mdf file.

I have an .mdf file, and I'd like to create a database from it on my computer. But I'd like to create i开发者_如何学编程t without attaching it to the .mdf file.

Is this possible?


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.


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'
0

精彩评论

暂无评论...
验证码 换一张
取 消