有没有办法将 SQL Server 2008 mdf 文件转换为 SQL Server Express 版本?
我有一个 mdf 文件,它是 SQL Server 2008 文件。我想将其转换为 SQL Server Express 或 SQL Compact 版本。
有什么工具可以转换吗?
I have a mdf file which is SQL Server 2008 file. I want to convert it to SQL Server Express or SQL Compact edition.
Is there any tool to convert it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 SQL Server - Express 或 Standard/Web/Developer - 文件格式没有区别。 SQL Server 2008 中的 MDF 将在 SQL Server 2008(或 2008 R2)Express 上运行,无需任何转换或修改。
您可以
.bak
文件中)并在 SQL Server 2008 Express 下还原它,或者:
不过,SQL Server Compact Edition 则完全不同 - 它由单个
.SDF
文件组成,无法从现有的 SQL Server 2008 MDF/LDF 文件集轻松创建......如果有任何有用的工具可以将数据从 SQL Server 2008 (MDF/LDF) 迁移到 SQL Server Compact Edition 4.0 (SDF) 格式,我本人也会很感兴趣...更新:快速说明搜索发现了一些有趣的候选者:
For SQL Server - Express or Standard/Web/Developer - there is no difference in the file formats. Your MDF from your SQL Server 2008 will work on SQL Server 2008 (or 2008 R2) Express without any conversion or modification.
You can
.bak
file) and restore it under SQL Server 2008 Expressor:
The SQL Server Compact Edition is quite a different story, though - it's made up of a single
.SDF
file and cannot be easily created from an existing SQL Server 2008 MDF/LDF set of files.... I would be interested myself if there are any useful tools out there to migrate data from SQL Server 2008 (MDF/LDF) to a SQL Server Compact Edition 4.0 (SDF) format...Update: a quickie search found a few interesting candidates:
除非您使用在 Express Edition 中无法使用的功能(例如分区),否则您的 2008 数据库也适用于 SQL Server 2008 Express。如果数据库当前附加在某处,您可以使用以下方法检查这些功能:
理想情况下,这将返回 0 行。如果它返回任何行,则很可能您正在使用不符合 Express 条件的功能。
如果数据库实际上仍然附加到 2008 实例,则备份/恢复比分离/附加要安全得多 - 这样,如果出现问题,您的原始数据库仍然完好无损。因此,如果已连接,您可以在 2008 实例上运行 BACKUP DATABASE 命令,然后在 Express 实例上运行 RESTORE DATABASE(可能使用 WITH MOVE 选项将文件存储在正确的位置)。 (更简单的方法是将数据库设置为离线,复制文件,然后再次将数据库设置为在线 - 但我仍然更喜欢备份/恢复路线。)
备份:
http://msdn.microsoft.com/en-us/library/ms186865%28SQL.100%29.aspx
恢复:
http://msdn.microsoft.com/en-us/library/ms186858%28SQL.100%29.aspx
如果您只有 MDF/LDF 文件,则在 SQL Server 上2008 Express 您应该能够使用 CREATE DATABASE...FOR ATTACH / FOR ATTACH_REBUILD_LOG。您可以在此处阅读有关语法的信息:
CREATE DATABASE:
http://msdn.microsoft.com/en-us/library/ms176061%28SQL.100%29.aspx
如果您遇到问题对于这些命令中的任何一个,请发布您尝试过的内容以及您收到的错误消息。
至于精简版,不,我不知道有任何工具可以为您转换数据库。两者之间的功能集甚至某些语言结构都不兼容。
Unless you use features that do not work in Express Edition (such as partitioning), your 2008 database is also eligible in SQL Server 2008 Express. If the database is currently attached somewhere, you can check for these features using:
Ideally this will return 0 rows. If it returns any rows, it is quite likely that you are using features not eligible in Express.
Also much safer to BACKUP/RESTORE than detach/attach if the database is in fact still attached to a 2008 instance - this way, if things go wrong, your original database is still intact. So if it is attached, you can run a BACKUP DATABASE command on the 2008 instance, then run a RESTORE DATABASE (probably using WITH MOVE options to store the files in the right location) on the Express instance. (Simpler still would be to set the database OFFLINE, copy the files, and set the database ONLINE again - but I still prefer the BACKUP/RESTORE route.)
BACKUP:
http://msdn.microsoft.com/en-us/library/ms186865%28SQL.100%29.aspx
RESTORE:
http://msdn.microsoft.com/en-us/library/ms186858%28SQL.100%29.aspx
If all you have is an MDF/LDF file, then on SQL Server 2008 Express you should be able to use CREATE DATABASE...FOR ATTACH / FOR ATTACH_REBUILD_LOG. You can read about the syntax here:
CREATE DATABASE:
http://msdn.microsoft.com/en-us/library/ms176061%28SQL.100%29.aspx
If you have issues with any of these commands, please post what you've tried and what error message you receive.
As for Compact Edition, no, I have no knowledge of any tools that will convert your database for you. The feature sets and even some of the language constructs are not compatible between the two.