简体   繁体   English

如何更新SQL Server数据库架构?

[英]How can I update my SQL Server database schema?

Usually throughout development of a project I will deploy frequently, just to make sure I wont have any problems in production. 通常在项目开发过程中我会经常部署,以确保我不会在生产中遇到任何问题。

Also, throughout development, I find myself changing the database's schema. 此外,在整个开发过程中,我发现自己正在改变数据库的模式。

How can I easily update the database in production? 如何在生产中轻松更新数据库?

I have been dropping the old database and reattaching the new one. 我一直在删除旧数据库并重新连接新数据库。 Is there a faster way to update the deployment database? 是否有更快的方式来更新部署数据库?

Thanks 谢谢

EDIT 编辑

What are some free tools for this? 有什么免费工具吗?

Maintain a list of all the change scripts that you apply to your dev database and apply them to the Production database when deploying. 维护应用于dev数据库的所有更改脚本的列表,并在部署时将它们应用于Production数据库。

Alternatively, use a third party tool that can compare the two schemas and provide a changescript which you can then run. 或者,使用可以比较两个模式的第三方工具,并提供可以随后运行的更改脚本。

I try to use tools like RedGate SQL Compare which will show you "diffs" between two versions and actually script out the components that are different. 我尝试使用像RedGate SQL Compare这样的工具,它会显示两个版本之间的“差异”,并实际编写不同的组件。 You can also make it a habit to script all of your database revisions so that you have an audit trail of changes you've made and can apply them in a programmatic way when you are ready to deploy. 您还可以习惯编写所有数据库修订的脚本,以便对已经进行的更改进行审计跟踪,并在准备部署时以编程方式应用它们。

Your best bet is to implement your changes as a set of diff scripts. 最好的办法是将更改作为一组diff脚本实现。 So rather than dropping a table and recreating it, you script is as ALTER TABLE. 因此,不是删除表并重新创建它,而是将脚本作为ALTER TABLE。

There are also tools out there that help you do this. 还有一些工具可以帮助你做到这一点。 If you keep a copy of the original and the new database, you can run a tool against the two which will generate SQL that will take you from one version to another. 如果保留原始数据库和新数据库的副本,则可以针对这两个数据库运行一个工具,该工具将生成将从一个版本带到另一个版本的SQL。

I personally like to keep full creation scripts updated, as well as maintaining an upgrade script, whenever I change the schema for a particular release. 我个人希望每当我更改特定版本的架构时,都会更新完整的创建脚本以及维护升级脚本。 I have used Red Gate SQL Compare, and it is a very good tool, but prefer to keep the scripts maintained. 我使用过Red Gate SQL Compare,它是一个非常好的工具,但更喜欢保持脚本。

Always write a script to make your schema changes. 始终编​​写脚本以更改架构。 Place the script in a promotion folder so that when you promote your changes, the scripts are executed to change each environment. 将脚本放在促销文件夹中,以便在提升更改时执行脚本以更改每个环境。

Try DBSourceTools. 试试DBSourceTools。
http://dbsourcetools.codeplex.com http://dbsourcetools.codeplex.com
Its open source, and will script an entire database 它的开源,并将脚本整个数据库
- tables, views, procs and data to disk, and then allow you to re-create that database through a deployment target. - 表,视图,过程和数据到磁盘,然后允许您通过部署目标重新创建该数据库。
It's specifically designed to help developers get their databases under source code control. 它专门用于帮助开发人员在源代码控制下获取数据库。

Generate Scripts向导完全符合我的需要。

Migrator Dot Net is an awesome tool for versioning your database. Migrator Dot Net是一个用于版本化数据库的强大工具。 It's hard to go back to manually keeping track of scripts and doing database comparisons after you've used migrations. 在使用迁移后,很难回到手动跟踪脚本和进行数据库比较。

Visual Studio Database Edition is quite good at this . Visual Studio数据库版非常擅长这一点 It keeps your entire schema in source scripts under source control along with the rest of your code. 它使源代码脚本中的整个架构与其余代码一起保持在源代码管理中。 It can analyze your schema for dependencies when you make a change. 当您进行更改时,它可以分析您的架构的依赖关系。 It can run best practices analysis. 它可以运行最佳实践分析。 And it can generate a .dbschema file that can is used by the deployment tool to upgrade your database to the current schema. 它可以生成.dbschema文件,部署工具可以使用该文件将数据库升级到当前架构。

You can actually automate this with continuos integration and build drops straight to test environment, staging environment and even production environment. 实际上,您可以通过continuos集成自动执行此操作,并直接构建测试环境,暂存环境甚至生产环境。 What that means is that when you check in into the test branch, the build machine will build product, run the build validation tests and deploy it on your development server. 这意味着当您签入测试分支时,构建机器将构建产品,运行构建验证测试并将其部署在开发服务器上。 When you reverse integrate from test branch to main branch, the build machine builds the product, runs the BVTs and deploys is on your staging test/acceptance server. 当您从测试分支反向集成到主分支时,构建机器构建产品,运行BVT并在您的分段测试/接受服务器上部署。 And when you integrate into the release branch the build machine will build, test and finally deploy on production. 当您集成到发布分支时,构建计算机将构建,测试并最终部署在生产中。 Now is true, not many orgs are ready to go that far and let the continuos build process deploy automatically on the live production servers and I reckon it is kinda radical thinking. 现在确实如此,没有多少组织准备好走这么远,让连续构建过程在现场生产服务器上自动部署,我认为这是一种激进的想法。 But I say you should trust more your automated BVTs and automated processes than any manual test and deployment. 但我说你应该比任何手动测试和部署更信任你的自动化BVT和自动化流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在SQL Server数据库模式中找到所有填充了100%空值的列? - How can I find all columns that are filled with 100% nulls in my SQL Server database schema? 更新 SQL Server 数据库架构 - Update SQL Server database schema 如何在项目设置中添加SQL Server数据库 - How can I add SQL Server Database in my project setup 如何自动更新SQL Server数据库? - How can I automate updating my SQL Server database? 如何将我的sql server 2008的架构导出到另一台计算机? - How can I export the schema of my sql server 2008 to another computer? 如何使用最新备份更新我的本地SQL Server数据库? - How to update my local SQL Server database with the latest backup? 如何将我的数据库上的所有sql server管理工作室激活作为可执行的tsql日志? - How can i get all my sql server managment studio activite on my database as a executable tsql log? django&sql-如何有效地存储和更新与数据库表中的记录关联的排序顺序信息? - django & sql - how can I efficiently store and update sort order information associated with records in my database table? 如何在添加到项目的SQL Server Express数据库中创建用户? - How can I create a user in SQL Server Express database I added to my project? 我无法连接到本地SQL Server数据库 - I can't connect to my local SQL Server database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM