SQL Server:升级数据库
我们有一款使用 Microsoft SQL Server 数据库的产品。 我们有客户使用该产品的各种旧版本。
在这种情况下,人们如何编写/构建他们的数据库升级脚本?
We've got a product that uses a Microsoft SQL Server database. We've got customers using various older versions of the product.
How do people write/structure their database upgrade scripts in this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一组版本间的补丁脚本。 在具有实时数据的生产系统上,这有点棘手,因为您可能还必须操作这些脚本中的数据。
Redgate SQL Compare Pro 是一个非常好的工具,用于生成这些脚本或对脚本执行 QA 功能(显然您不应该真正将它用于这两个角色)。 由于涉及实时客户数据,因此您必须对升级进行回归测试。
我认为没有一个简单的方法可以做到这一点。 您将必须开发脚本并测试它所做的任何数据操作。 对一些有用的升级集进行不同版本的测试。 这里的关键是安排一个生产镜像测试环境,您可以在将补丁应用到实时系统之前在其中测试补丁。
PS 在实际最终运行补丁脚本之前,不要忘记在生产数据库上备份和测试恢复,但您已经知道了;-}
You need a set of release-to-release patch scripts. On production systems with live data this is a bit trickier as you may also have to manipulate data in these scripts.
Redgate SQL Compare Pro is quite a good tool for generating these scripts or doing QA functions on scripts (obviously you shouldn't really use it for both roles). Because you have live customer data involved you will have to regression test the upgrades.
I don't think there's an easy way to do this. You will have to develop the script and test any data manipulations that it does. Do the tests from version to version for some useful set of upgrades. The key here is to arrange a production mirror test environment that you can test the patches in before you apply them to a live system.
P.S. don't forget to back up and test restore on the production database before you actually finally run the patch script, but you already knew that ;-}
我们有一个 SQL 脚本可以执行全新安装和升级。 安装 SQL Express 或完整 SQL Server 后,我们运行此脚本执行以下操作:
我们不断扩展此脚本,因此每个版本只会添加到此 SQL 脚本文件。 这意味着我们可以在生产系统上运行此脚本以将其更新到最新架构,使用新安装的脚本从头开始创建架构。
这样我们就可以保证升级脚本甚至可以将最旧的安装升级到最新版本。
We have one SQL script that does both a clean installation and an upgrade. After installing SQL Express or full SQL server, we run this script that does the following:
We keep on extending this script, so each release will only add to this SQL script file. This means we can run this script on production systems to update them to the latest schema use the script for new installations to create the schema from scratch.
This way we're guaranteed that the upgrade script will bring even the oldest installation up to the latest version.