SQL - 如何使用 MS SQL 2008 R2 备份数据库并导出为 MDF 文件
我已经使用 MS SQL Server 2008 R2(即 MS SQL Server Management Studio)中的一些表创建了一个数据库“测试”。
现在,我需要将此数据库导出为 MDF 文件。
我应该怎么办?
I have created a database "test" with some tables in MS SQL Server 2008 R2 (i.e. MS SQL Server Management Studio).
Now, I need to export this database as a MDF file.
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您希望能够将数据库附加到另一台服务器上,那么您可以执行以下操作:
(右键单击
数据库
,然后单击附加
) 这是您将找到 MDF 文件的路径:If you mean that you want to be able to attach the database on another server, then this is what you can do:
Detach
)Databases
and clickAttach
)This is the path where you will find MDF file:
在 Management Studio 中右键单击数据库 ->分离。然后您就可以将 MDF 文件导出到任何您想要的地方:)
right-click on database from Management Studio -> Detach. Then you have the MDF file you can export to wherever you want :)
我认为最好的方法是从 SQL Server 创建一个
.bak
文件。右键点击数据库=>
任务
=>备份
->在Source
中选择数据库,然后点击OK
。I think the best way is to create a
.bak
file from SQL Server .Right click on the database =>
Task
=>Back Up
-> Choose the database inSource
, and hitOK
.如果您想要的是远程服务器 (SQL Server 2005) 上的 SQLEXPRESS/MDF 本地文件的副本,
您可以右键单击 db.mdf 文件上的“服务器资源管理器”,然后按< strong>“发布到提供商...”
您可以选择与 SQL Server 2005、2008 等的各种兼容性。
输出是 .sql 查询文件..
遇到了这个问题并认为这将是一个很好的替代答案,因为我是通过搜索完全相同的东西来到这里的!
If what you want is a replica of your SQLEXPRESS/MDF local file- on a remote server (SQL Server 2005)
You can right click in the "Server Explorer" on your db.mdf file and press "Publish to provider..."
You can choose a variety of compatibilities with SQL Server 2005, 2008, etc.
The output is a .sql query file ..
Came across this question and thought this would be a good alternative answer, since I got here by searching for the exact same thing!
C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\
这是您找到 MDF 文件的路径
C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\
This is the path where you will find MDF file
如果您使用的是 Visual Studio,请转到SQL Server 对象资源管理器。找到所需的数据库,右键单击并选择属性。在属性选项卡中,查找数据文件,旁边是您的 mdf 文件的位置。
If you are in Visual Studio, go to SQL Server Object Explorer. Find the database you want, right click and select properties. In the properties tab, look for Data File, next to it will be the location for your mdf file.
根据我的经验,使用命令 sp_detach_db (MSDN) 和sp_attach_db (MSDN)。我试图附加一个在分离时处于脱机状态的数据库,并且当我使用右键单击上下文菜单中的“附加”选项时,SQL Server Management Studio (2014) 不断崩溃。这些命令有效 - 希望这可以节省一些时间。
注意:如果您在尝试执行附加命令时看到访问被拒绝,请以管理员身份运行 SSMS
In my experience, its easier to use the commands sp_detach_db (MSDN) and sp_attach_db (MSDN). I was trying to attach a database that was offline when detached and SQL Server Management Studio (2014) kept crashing when I used the Attach option from the right-click context menu. The commands worked - hope this saves someone some time.
NOTE: Run SSMS as an administrator if you see an access denied while trying to execute the attach command
转到路径 C:\Users\你的电脑名称
然后你会在这里找到 mdf , ldf 文件
Go to the path C:\Users\your pc name
then you will find mdf , ldf file here