SQL Server:从 .mdf 导入数据库?
我的本地盒子上有一个 .mdf 文件。
我的本地机器上安装了 SQL Server 2008 Express 和 SQL Management Studio 2008 Express。
我究竟如何将此 .mdf 文件作为新数据库导入到我的 SQL Server 中?
这似乎是一项极其常见的任务,必须在全球范围内每天执行数千次,而且我不知道如何在 Management Studio Express 中执行此操作。
我缺少什么?
I have an .mdf file on my local box.
I have SQL Server 2008 Express and SQL Management Studio 2008 Express installed on my local box.
How in the world do I import this .mdf file as a new database into my SQL Server?
This seems like a ridiculously common task that must be performed thousands of times a day across the globe, and I cannot figure out how to do it in Management Studio Express.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
打开 SQL Management Studio Express 并登录到要附加数据库的服务器。在“对象资源管理器”窗口中,右键单击“数据库”文件夹并选择“附加...”“附加数据库”窗口将打开;在该窗口中单击“添加...”,然后导航到您的 .MDF 文件并单击“确定”。再次单击“确定”完成数据库附加,您就完成了。该数据库应该可供使用。
此致 :)
Open SQL Management Studio Express and log in to the server to which you want to attach the database. In the 'Object Explorer' window, right-click on the 'Databases' folder and select 'Attach...' The 'Attach Databases' window will open; inside that window click 'Add...' and then navigate to your .MDF file and click 'OK'. Click 'OK' once more to finish attaching the database and you are done. The database should be available for use.
best regards :)
:如何:将数据库文件附加到 SQL Server Express
请参阅 通过 sqlcmd 访问数据库:
然后发出命令:
See: How to: Attach a Database File to SQL Server Express
Login to the database via sqlcmd:
And then issue the commands:
要执行此操作,请参阅下图:
下一步是添加 *.mdf 文件,
非常重要,.mdf 文件必须位于 C:......\MSSQL12 .SQLEXPRESS\MSSQL\DATA
现在删除日志文件
To perform this operation see the next images:
and next step is add *.mdf file,
very important, the .mdf file must be located in C:......\MSSQL12.SQLEXPRESS\MSSQL\DATA
Now remove the log file
除了上面 @daniele3004 发布的答案中提到的步骤之外,我还必须以管理员身份打开 SSMS,否则它会显示“主文件是只读”错误。
转到“开始”菜单,导航到 SSMS 链接,右键单击 SSMS 链接,选择以管理员身份运行。然后执行上述步骤。
Apart from steps mentioned in posted answers by @daniele3004 above, I had to open SSMS as Administrator otherwise it was showing Primary file is read only error.
Go to Start Menu , navigate to SSMS link , right click on the SSMS link , select Run As Administrator. Then perform the above steps.
如果您没有 LDF 文件,则:
1) 将 MDF 放入
C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\
2) 在 ssms 中,转到 <代码>数据库->附加并添加 MDF 文件。它不会让您以这种方式添加它,但它会告诉您其中包含的数据库名称。
3) 确保您运行 ssms.exe 的用户有权访问此 MDF 文件。
4) 现在您知道了 DbName,请运行
参考:https://dba.stackexchange.com/问题/12089/attaching-mdf-without-ldf
If you do not have an LDF file then:
1) put the MDF in the
C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\
2) In ssms, go to
Databases -> Attach
and add the MDF file. It will not let you add it this way but it will tell you the database name contained within.3) Make sure the user you are running ssms.exe as has acccess to this MDF file.
4) Now that you know the DbName, run
Reference: https://dba.stackexchange.com/questions/12089/attaching-mdf-without-ldf
在 docker 中托管 MS SQL 时,如下所示
:
When hosting MS SQL in docker like:
it's enough to: