我可以将一个 .mdf 文件与多个 DBMS(SQL Server 2008 和 2012)一起使用吗?

在家里,我安装了 SQL Server 2008 R2 (Express),它附加到某个 .mdf 文件.我正在安装 SQL Server 2012(开发人员版).我可以将 2012 附加到同一个 .mdf 文件吗?从逻辑上讲,只要 SQL Server 的两个实例中只有一个正在运行,这似乎就可以工作.想法?

At home, I have SQL Server 2008 R2 (Express) installed which is attached to a certain .mdf file. I'm in the process of installing SQL Server 2012 (Developer Edition). Can I attach 2012 to the same .mdf file? Logically, it seems like this would work as long as only one of the two instances of SQL Server is running. Thoughts?

推荐答案

您可以向上 - 从旧版本到新版本,例如您可以在 2008 R2 中备份数据库并在 2012 实例中恢复该备份 - 但您不能从 SQL Server 的较新版本附加/分离或备份/恢复数据库一直到旧版本 - 内部文件结构差异太大,无法支持向后兼容性.

You can go upwards - from an older version to a newer one, e.g. you can backup your database in 2008 R2 and restore that backup in your 2012 instance - but you CANNOT attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility.

另外:由于 .mdf 的内部文件结构非常不同并且特定于每个 SQL Server 版本,您将不能能够使用相同的.mdf 来自两个不同的 SQL Server 版本.那肯定不行.

Also: since the internal file structures of the .mdf are very much different and specific to each version of SQL Server, you will NOT be able to use the same .mdf from two different SQL Server versions. That definitely won't work.

你可以通过

  • 在所有机器上使用相同版本的 SQL Server - 然后您可以轻松地在实例之间备份/恢复数据库

  • using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances

否则,您可以在 SQL Server Management Studio (Tasks >) 中为结构(表、视图、存储过程等)和内容(表中包含的实际数据)创建数据库脚本; 生成脚本) 或使用第三方工具

otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool

或者您可以使用第三方工具,例如 Red-Gate 的 SQL 比较 和 SQL 数据比较 在源和目标之间进行差异化",根据这些差异生成更新脚本,然后在目标平台上执行这些脚本;这适用于不同的 SQL Server 版本.

or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.

相关文章